WeixinMessageSend.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace Cas\Dao;
  3. use KIF\Dao\DBAgileDev;
  4. use KIF\Verify;
  5. /**
  6. *
  7. * 微信群发任务
  8. * @author lishumingoo@gmail.com
  9. */
  10. class WeixinMessageSend extends DBAgileDev {
  11. protected $tableName = 'weixin_message_send';
  12. /**
  13. * 数据库里的真实字段
  14. * @var array
  15. */
  16. protected $other_field = array(
  17. 'description',
  18. 'msg_id',
  19. 'msgType',
  20. 'status',
  21. 'send_time',
  22. );
  23. /**
  24. * 群发消息类型:文字
  25. * @var string
  26. */
  27. const TYPE_TEXT = 'text';
  28. /**
  29. * 群发消息类型:图片
  30. * @var string
  31. */
  32. const TYPE_IMG = 'image';
  33. /**
  34. * 群发消息类型:图文
  35. * @var string
  36. */
  37. const TYPE_TEXT_AND_IMG = 'news';
  38. /**
  39. * 群发消息类型:语音
  40. * @var string
  41. */
  42. const TYPE_VOICE = 'voice';
  43. /**
  44. * 群发任务状态:等待发送
  45. * @var int
  46. */
  47. const STATUS_WAIT_SEND = 100;
  48. /**
  49. * 群发任务状态:发送成功
  50. * @var int
  51. */
  52. const STATUS_SEND_SUCCESS = 200;
  53. /**
  54. * 群发任务状态:发送是吧
  55. * @var unknown
  56. */
  57. const STATUS_SEND_FAIL = 240;
  58. /**
  59. * 群发任务状态:发送完成
  60. * @var int
  61. */
  62. const STATUS_SEND_DONE = 300;
  63. /**
  64. * 群发任务状态:取消发送
  65. * @var int
  66. */
  67. const STATUS_CLOSED_SEND = 400;
  68. static private $statusDesc = array(
  69. self::STATUS_WAIT_SEND => array(
  70. 'desc' => '等待发送',
  71. 'kw' => 'STATUS_WAIT_SEND',
  72. ),
  73. self::STATUS_SEND_SUCCESS => array(
  74. 'desc' => '发送成功',
  75. 'kw' => 'STATUS_SEND_SUCCESS',
  76. ),
  77. self::STATUS_SEND_FAIL => array(
  78. 'desc' => '发送失败',
  79. 'kw' => 'STATUS_SEND_FAIL',
  80. ),
  81. self::STATUS_SEND_DONE => array(
  82. 'desc' => '发送完成',
  83. 'kw' => 'STATUS_SEND_DONE',
  84. ),
  85. self::STATUS_CLOSED_SEND => array(
  86. 'desc' => '取消发送',
  87. 'kw' => 'STATUS_CLOSED_SEND',
  88. ),
  89. );
  90. static public function getsStatusDesc() {
  91. return self::$statusDesc;
  92. }
  93. /**
  94. *
  95. * 置为“等待发送”
  96. * @param int $id
  97. * @return boolean
  98. */
  99. public function setWaitSend($id) {
  100. $statusCondition = array(self::STATUS_CLOSED_SEND);
  101. return $this->updateStatus($id, self::STATUS_WAIT_SEND, $statusCondition);
  102. }
  103. /**
  104. *
  105. * 置为“取消发送”
  106. * @param int $id
  107. * @return boolean
  108. */
  109. public function setClosedSend($id) {
  110. $statusCondition = array(self::STATUS_WAIT_SEND);
  111. return $this->updateStatus($id, self::STATUS_CLOSED_SEND, $statusCondition);
  112. }
  113. public function updateStatus($id, $status, array $statusCondition = null) {
  114. if (!Verify::unsignedInt($id)) {
  115. return false;
  116. }
  117. if (!in_array($status, array_keys(self::$statusDesc))) {
  118. return false;
  119. }
  120. $tableInfo = array(
  121. 'status' => $status,
  122. 'update_time' => time(),
  123. );
  124. $condition = array(
  125. 'id' => $id,
  126. );
  127. if (!is_null($statusCondition)) {
  128. $condition['status'] = $statusCondition;
  129. }
  130. return $this->update($tableInfo, $condition);
  131. }
  132. }