DataDownload.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\download;
  12. use think\Db;
  13. use traits\ModelTrait;
  14. use basic\ModelBasic;
  15. use app\admin\model\download\DataDownloadCategpry;
  16. use app\admin\model\system\RecommendRelation;
  17. use app\admin\model\system\WebRecommendRelation;
  18. use service\SystemConfigService;
  19. use app\admin\model\merchant\Merchant;
  20. use service\WechatTemplateService;
  21. use app\wap\model\routine\RoutineTemplate;
  22. use app\admin\model\wechat\WechatUser;
  23. /**资料 model
  24. * Class DataDownload
  25. * @package app\admin\model\download
  26. */
  27. class DataDownload extends ModelBasic
  28. {
  29. use ModelTrait;
  30. /**字段过滤
  31. * @param string $alias
  32. * @param null $model
  33. * @return DataDownload
  34. */
  35. public static function PreWhere($alias = '', $model = null)
  36. {
  37. if (is_null($model)) $model = new self();
  38. if ($alias) {
  39. $model = $model->alias($alias);
  40. $alias .= '.';
  41. }
  42. return $model->where([$alias . 'is_show' => 1, $alias . 'is_del' => 0, $alias . 'status' => 1]);
  43. }
  44. /**条件处理
  45. * @param $where
  46. * @return DataDownload
  47. */
  48. public static function setWhere($where)
  49. {
  50. $model = new self();
  51. $time['data'] = '';
  52. if (isset($where['start_time']) && isset($where['end_time']) && $where['start_time'] != '' && $where['end_time'] != '') {
  53. $time['data'] = $where['start_time'] . ' - ' . $where['end_time'];
  54. $model = $model->getModelTime($time, $model, 'add_time');
  55. }
  56. if (isset($where['title']) && $where['title']) {
  57. $model = $model->where('title|id|abstract', 'like', "%$where[title]%");
  58. }
  59. if (isset($where['cate_id']) && $where['cate_id']) {
  60. $model = $model->where('cate_id', $where['cate_id']);
  61. }
  62. if (isset($where['mer_id']) && $where['mer_id'] != '') {
  63. $model = $model->where('mer_id', $where['mer_id']);
  64. }
  65. if (isset($where['is_show']) && $where['is_show'] != '') {
  66. $model = $model->where('is_show', $where['is_show']);
  67. }
  68. if (isset($where['status']) && $where['status'] != '') {
  69. $model = $model->where('status', $where['status']);
  70. } else {
  71. $model = $model->where('status', 'in', [-1, 0]);
  72. }
  73. return $model->where('is_del', 0);
  74. }
  75. /**获取列表
  76. * @param $where
  77. * @return array
  78. * @throws \think\Exception
  79. */
  80. public static function get_download_list($where)
  81. {
  82. $data = self::setWhere($where)->order('sort DESC,id DESC')
  83. ->page((int)$where['page'], (int)$where['limit'])->select();
  84. foreach ($data as $key => $item) {
  85. $item['recommend'] = RecommendRelation::where('a.link_id', $item['id'])->where('a.type', 14)->alias('a')
  86. ->join('__RECOMMEND__ r', 'a.recommend_id=r.id')->column('a.id,r.title');
  87. $item['web_recommend'] = WebRecommendRelation::where('a.link_id', $item['id'])->where('a.type', 3)->alias('a')
  88. ->join('__WEB_RECOMMEND__ r', 'a.recommend_id=r.id')->column('a.id,r.title');
  89. $item['add_time'] = ($item['add_time'] != 0 || $item['add_time']) ? date('Y-m-d H:i:s', $item['add_time']) : '';
  90. $item['cate_name'] = DataDownloadCategpry::where('id', $item['cate_id'])->value('title');
  91. if ($item['mer_id']) {
  92. $item['mer_name'] = Merchant::where('id', $item['mer_id'])->value('mer_name');
  93. } else {
  94. $item['mer_name'] = '总平台';
  95. }
  96. }
  97. $data = count((array)$data) ? $data->toArray() : [];
  98. $count = self::setWhere($where)->count();
  99. return compact('data', 'count');
  100. }
  101. /**获取资料
  102. * @param $where
  103. */
  104. public static function dataDownloadLists($where, $source)
  105. {
  106. $data = self::setWhere($where)->where('id', 'not in', $source)->page($where['page'], $where['limit'])->select();
  107. foreach ($data as $key => $item) {
  108. if ($item['mer_id']) {
  109. $item['mer_name'] = Merchant::where('id', $item['mer_id'])->value('mer_name');
  110. } else {
  111. $item['mer_name'] = '总平台';
  112. }
  113. }
  114. $count = self::setWhere($where)->where('id', 'not in', $source)->count();
  115. return compact('data', 'count');
  116. }
  117. /**获取列表
  118. * @param $where
  119. * @return array
  120. * @throws \think\Exception
  121. */
  122. public static function get_download_examine_list($where)
  123. {
  124. $data = self::setWhere($where)->order('sort DESC,id DESC')
  125. ->page((int)$where['page'], (int)$where['limit'])->select();
  126. foreach ($data as $key => $item) {
  127. $item['fail_time'] = date('Y-m-d H:i:s', $item['fail_time']);
  128. $item['add_time'] = ($item['add_time'] != 0 || $item['add_time']) ? date('Y-m-d H:i:s', $item['add_time']) : '';
  129. $item['cate_name'] = DataDownloadCategpry::where('id', $item['cate_id'])->value('title');
  130. if ($item['mer_id']) {
  131. $item['mer_name'] = Merchant::where('id', $item['mer_id'])->value('mer_name');
  132. } else {
  133. $item['mer_name'] = '总平台';
  134. }
  135. }
  136. $data = count((array)$data) ? $data->toArray() : [];
  137. $count = self::setWhere($where)->count();
  138. return compact('data', 'count');
  139. }
  140. /**审核失败
  141. * @param $id
  142. * @param $fail_msg
  143. * @return bool
  144. * @throws \think\exception\DbException
  145. */
  146. public static function changeFail($id, $mer_id, $fail_message)
  147. {
  148. $fail_time = time();
  149. $status = -1;
  150. $uid = Merchant::where('id', $mer_id)->value('uid');
  151. try {
  152. $wechat_notification_message = SystemConfigService::get('wechat_notification_message');
  153. if ($wechat_notification_message == 1) {
  154. WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($uid), WechatTemplateService::EXAMINE_RESULT, [
  155. 'first' => '尊敬的讲师,您添加的资料审核结果已出。',
  156. 'keyword1' => '审核失败',
  157. 'keyword2' => date('Y-m-d H:i:s', time()),
  158. 'remark' => '失败原因:' . $fail_message
  159. ], '');
  160. } else {
  161. $dat['phrase5']['value'] = '资料审核失败';
  162. $dat['time24']['value'] = date('Y-m-d H:i:s', time());
  163. $dat['thing4']['value'] = '资料失败原因:' . $fail_message;
  164. RoutineTemplate::sendExamineResult($dat, $uid, '');
  165. }
  166. } catch (\Exception $e) {
  167. }
  168. return self::edit(compact('fail_time', 'fail_message', 'status'), $id);
  169. }
  170. /**审核成功
  171. * @param $id
  172. * @return bool
  173. */
  174. public static function changeSuccess($id, $mer_id)
  175. {
  176. $success_time = time();
  177. $status = 1;
  178. $uid = Merchant::where('id', $mer_id)->value('uid');
  179. try {
  180. $wechat_notification_message = SystemConfigService::get('wechat_notification_message');
  181. if ($wechat_notification_message == 1) {
  182. WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($uid), WechatTemplateService::EXAMINE_RESULT, [
  183. 'first' => '尊敬的讲师,您添加的资料审核结果已出。',
  184. 'keyword1' => '审核成功',
  185. 'keyword2' => date('Y-m-d H:i:s', time()),
  186. 'remark' => '感恩您的努力付出,谢谢!'
  187. ], '');
  188. } else {
  189. $dat['phrase5']['value'] = '资料审核成功';
  190. $dat['time24']['value'] = date('Y-m-d H:i:s', time());
  191. $dat['thing4']['value'] = '您添加的资料审核结果已出!';
  192. RoutineTemplate::sendExamineResult($dat, $uid, '');
  193. }
  194. } catch (\Exception $e) {
  195. }
  196. return self::edit(compact('status', 'success_time'), $id);
  197. }
  198. }