人人商城

job.table.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. class JobTable extends We7Table {
  8. protected $tableName = 'core_job';
  9. protected $field = array('type', 'payload', 'status', 'handled', 'uniacid', 'title', 'total', 'createtime', 'endtime', 'updatetime', 'isdeleted', 'uid');
  10. protected $default = array('status'=>0, 'handled'=>0, 'total'=>0, 'createtime'=>'custom', 'updatetime'=>'custom', 'isdeleted'=>0, 'uid'=>0);
  11. const DELETE_ACCOUNT = 10;
  12. const SYNC_FANS = 20;
  13. protected function defaultCreatetime() {
  14. return TIMESTAMP;
  15. }
  16. protected function defaultUpdatetime() {
  17. return TIMESTAMP;
  18. }
  19. public function jobs() {
  20. return $this->where('status', 0)->getall();
  21. }
  22. public function alljobs() {
  23. return $this->getall();
  24. }
  25. public function exitsJob($uniacid, $type)
  26. {
  27. $result = table('job')->where('uniacid', $uniacid)->where('type', $type)->get();
  28. return !empty($result);
  29. }
  30. public function createDeleteAccountJob($uniacid, $accountName, $total, $uid)
  31. {
  32. if ($this->exitsJob($uniacid, self::DELETE_ACCOUNT)) {
  33. return error(1, '任务已存在');
  34. }
  35. $data = array(
  36. 'type' => self::DELETE_ACCOUNT,
  37. 'title'=> "删除{$accountName}的素材数据",
  38. 'uniacid'=>$uniacid,
  39. 'total'=> $total,
  40. 'uid'=>$uid
  41. );
  42. return $this->createJob($data);
  43. }
  44. public function createSyncFans($uniacid, $accountName, $total ) {
  45. if ($this->exitsJob($uniacid, self::SYNC_FANS)) {
  46. return error(1, '同步任务已存在');
  47. }
  48. $data = array(
  49. 'type' => self::SYNC_FANS,
  50. 'title'=> "同步 $accountName ($uniacid) 的公众号粉丝数据",
  51. 'uniacid'=>$uniacid,
  52. );
  53. return $this->createJob($data);
  54. }
  55. private function createJob($data)
  56. {
  57. $this->fill($data);
  58. $result = $this->save();
  59. if ($result) {
  60. return pdo_insertid();
  61. }
  62. return $result;
  63. }
  64. public function clear($uid, $isfounder) {
  65. $table = table('job')
  66. ->where('status', 1)
  67. ->fill('isdeleted', 1);
  68. if (!$isfounder) {
  69. $table->where('uid', $uid);
  70. }
  71. return $table->save();
  72. }
  73. }