Plan.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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\study;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\admin\model\system\RecommendRelation;
  15. use app\admin\model\system\WebRecommendRelation;
  16. /**
  17. * Class Lecturer 讲师
  18. * @package app\admin\model\special
  19. */
  20. class Plan extends ModelBasic
  21. {
  22. use ModelTrait;
  23. public function setShelfTimeAttr($val) {
  24. return $val ? strtotime($val) : time();
  25. }
  26. public function getShelfTimeAttr($val) {
  27. return $val ? date('Y-m-d H:i:s',$val) : '';
  28. }
  29. //设置where条件
  30. public static function setWhere($where, $alirs = '', $model = null)
  31. {
  32. $model = $model === null ? new self() : $model;
  33. $model = $alirs !== '' ? $model->alias($alirs) : $model;
  34. $alirs = $alirs === '' ? $alirs : $alirs . '.';
  35. $model = $model->where("{$alirs}is_del", 0);
  36. if (isset($where['is_show']) && $where['is_show'] !== '') $model = $model->where("{$alirs}is_show", $where['is_show']);
  37. if ($where['title'] && $where['title']) $model = $model->where("{$alirs}lecturer_name", 'LIKE', "%$where[title]%");
  38. $model = $model->order("{$alirs}shelf_time desc");
  39. return $model;
  40. }
  41. public static function getRecommendLecturerList($where, $lecturer)
  42. {
  43. $data = self::setWhere($where)->where('id', 'not in', $lecturer)->page((int)$where['page'], (int)$where['limit'])->select();
  44. $data = count($data) ? $data->toArray() : [];
  45. $count = self::setWhere($where)->where('id', 'not in', $lecturer)->count();
  46. return compact('data', 'count');
  47. }
  48. public static function setMerWhere($where, $alirs = '', $model = null)
  49. {
  50. $model = $model === null ? new self() : $model;
  51. $model = $alirs !== '' ? $model->alias($alirs) : $model;
  52. $alirs = $alirs === '' ? $alirs : $alirs . '.';
  53. $model = $model->where("{$alirs}is_del", 0);
  54. if (isset($where['is_show']) && $where['is_show'] !== '') $model = $model->where("{$alirs}is_show", $where['is_show']);
  55. if ($where['title'] && $where['title']) $model = $model->where("{$alirs}lecturer_name", 'LIKE', "%$where[title]%");
  56. $model = $model->order("{$alirs}sort desc");
  57. $model = $model->join('Merchant m', 'l.mer_id=m.id', 'left')->field('l.*,m.status,m.is_source');
  58. return $model;
  59. }
  60. /**计划列表
  61. * @param $where
  62. * @return array
  63. * @throws \think\Exception
  64. */
  65. public static function getLecturerList($where)
  66. {
  67. $data = self::setWhere($where, 'p')->page((int)$where['page'], (int)$where['limit'])->select();
  68. $data = count($data) ? $data->toArray() : [];
  69. $count = self::setWhere($where, 'p')->count();
  70. return compact('data', 'count');
  71. }
  72. /**
  73. * 删除讲师
  74. * @param $id
  75. * @return bool|int
  76. * @throws \think\exception\DbException
  77. */
  78. public static function delPlan($id)
  79. {
  80. $plan = self::get($id);
  81. if (!$plan) return self::setErrorInfo('删除的数据不存在');
  82. // Special::where('is_del', 0)->where('id', $id)->update(['is_show' => 0, 'is_del' => 1]);
  83. // if ($lecturer['mer_id'] > 0) {
  84. // $merchant = Merchant::get($lecturer['mer_id']);
  85. // if ($merchant) {
  86. // Merchant::where('id', $lecturer['mer_id'])->update(['is_del' => 1]);
  87. // User::where('uid', $merchant['uid'])->update(['business' => 0]);
  88. // MerchantAdmin::where('mer_id', $lecturer['mer_id'])->update(['is_del' => 1]);
  89. // DownloadModel::where(['is_del' => 0, 'mer_id' => $lecturer['mer_id']])->update(['is_show' => 0, 'is_del' => 1]);
  90. // ProductModel::where(['is_del' => 0, 'mer_id' => $lecturer['mer_id']])->update(['is_show' => 0, 'is_del' => 1]);
  91. // EventRegistrationModel::where(['is_del' => 0, 'mer_id' => $lecturer['mer_id']])->update(['is_show' => 0, 'is_del' => 1]);
  92. // }
  93. // }
  94. return self::where('id', $id)->update(['is_del' => 1]);
  95. }
  96. /**获取商户id
  97. * @param $id
  98. */
  99. public static function getMerId($id)
  100. {
  101. return self::where('id', $id)->value('mei_id');
  102. }
  103. /**讲师课程订单
  104. * @param $lecturer_id
  105. */
  106. public static function lecturerOrderList($where)
  107. {
  108. $model = self::getOrderWhere($where)->field('a.order_id,a.pay_price,a.pay_type,a.paid,a.status,a.total_price,a.refund_status,a.type,s.title,r.nickname,a.uid');
  109. $data = ($data = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
  110. foreach ($data as $key => &$value) {
  111. if ($value['paid'] == 0) {
  112. $value['status_name'] = '未支付';
  113. } else if ($value['paid'] == 1 && $value['status'] == 0 && $value['refund_status'] == 0 && $value['type'] != 2) {
  114. $value['status_name'] = '已支付';
  115. } else if ($value['paid'] == 1 && $value['status'] == 0 && $value['refund_status'] == 1 && $value['type'] != 2) {
  116. $value['status_name'] = '退款中';
  117. } else if ($value['paid'] == 1 && $value['status'] == 0 && $value['refund_status'] == 2 && $value['type'] != 2) {
  118. $value['status_name'] = '已退款';
  119. }
  120. if ($value['nickname']) {
  121. $value['nickname'] = $value['nickname'] . '/' . $value['uid'];
  122. } else {
  123. $value['nickname'] = '暂无昵称/' . $value['uid'];
  124. }
  125. if ($value['paid'] == 1) {
  126. switch ($value['pay_type']) {
  127. case 'weixin':
  128. $value['pay_type_name'] = '微信支付';
  129. break;
  130. case 'yue':
  131. $value['pay_type_name'] = '余额支付';
  132. break;
  133. case 'zhifubao':
  134. $value['pay_type_name'] = '支付宝支付';
  135. break;
  136. default:
  137. $value['pay_type_name'] = '其他支付';
  138. break;
  139. }
  140. } else {
  141. switch ($value['pay_type']) {
  142. default:
  143. $value['pay_type_name'] = '未支付';
  144. break;
  145. }
  146. }
  147. }
  148. $count = self::getOrderWhere($where)->count();
  149. return compact('count', 'data');
  150. }
  151. /**条件处理
  152. * @param $where
  153. * @return StoreOrderModel
  154. */
  155. public static function getOrderWhere($where)
  156. {
  157. $model = StoreOrderModel::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT')
  158. ->join('Special s', 'a.cart_id=s.id')
  159. ->where('a.type', 0)->where('a.paid', 1);
  160. if ($where['lecturer_id']) {
  161. $model = $model->where('s.lecturer_id', $where['lecturer_id']);
  162. }
  163. if ($where['data'] !== '') {
  164. $model = self::getModelTime($where, $model, 'a.add_time');
  165. }
  166. $model = $model->order('a.id desc');
  167. return $model;
  168. }
  169. /**
  170. * 处理订单金额
  171. * @param $where
  172. * @return array
  173. */
  174. public static function getOrderPrice($where)
  175. {
  176. $price = array();
  177. $price['pay_price'] = 0;//支付金额
  178. $price['pay_price_wx'] = 0;//微信支付金额
  179. $price['pay_price_yue'] = 0;//余额支付金额
  180. $price['pay_price_zhifubao'] = 0;//支付宝支付金额
  181. $list = self::getOrderWhere($where)->field([
  182. 'sum(a.total_num) as total_num',
  183. 'sum(a.pay_price) as pay_price',
  184. ])->find()->toArray();
  185. $price['total_num'] = $list['total_num'];//商品总数
  186. $price['pay_price'] = $list['pay_price'];//支付金额
  187. $list = self::getOrderWhere($where)->field('sum(a.pay_price) as pay_price,a.pay_type')->group('a.pay_type')->select()->toArray();
  188. foreach ($list as $v) {
  189. if ($v['pay_type'] == 'weixin') {
  190. $price['pay_price_wx'] = $v['pay_price'];
  191. } elseif ($v['pay_type'] == 'yue') {
  192. $price['pay_price_yue'] = $v['pay_price'];
  193. } elseif ($v['pay_type'] == 'zhifubao') {
  194. $price['pay_price_zhifubao'] = $v['pay_price'];
  195. } else {
  196. $price['pay_price_other'] = $v['pay_price'];
  197. }
  198. }
  199. $price['order_sum'] = self::getOrderWhere($where)->count();
  200. return $price;
  201. }
  202. public static function getBadge($where)
  203. {
  204. $price = self::getOrderPrice($where);
  205. return [
  206. [
  207. 'name' => '订单数量',
  208. 'field' => '件',
  209. 'count' => $price['order_sum'],
  210. 'background_color' => 'layui-bg-blue',
  211. 'col' => 4
  212. ],
  213. [
  214. 'name' => '售出课程',
  215. 'field' => '件',
  216. 'count' => $price['total_num'],
  217. 'background_color' => 'layui-bg-blue',
  218. 'col' => 4
  219. ],
  220. [
  221. 'name' => '订单金额',
  222. 'field' => '元',
  223. 'count' => $price['pay_price'],
  224. 'background_color' => 'layui-bg-blue',
  225. 'col' => 4
  226. ],
  227. [
  228. 'name' => '微信支付金额',
  229. 'field' => '元',
  230. 'count' => $price['pay_price_wx'],
  231. 'background_color' => 'layui-bg-blue',
  232. 'col' => 4
  233. ],
  234. [
  235. 'name' => '余额支付金额',
  236. 'field' => '元',
  237. 'count' => $price['pay_price_yue'],
  238. 'background_color' => 'layui-bg-blue',
  239. 'col' => 4
  240. ],
  241. [
  242. 'name' => '支付宝支付金额',
  243. 'field' => '元',
  244. 'count' => $price['pay_price_zhifubao'],
  245. 'background_color' => 'layui-bg-blue',
  246. 'col' => 4
  247. ]
  248. ];
  249. }
  250. /**生成讲师
  251. * @param $data
  252. * @param $mer_id
  253. * @return object
  254. */
  255. public static function addLecturer($data, $mer_id)
  256. {
  257. $array = [
  258. 'mer_id' => $mer_id,
  259. 'lecturer_name' => $data['merchant_name'],
  260. 'lecturer_head' => $data['merchant_head'],
  261. 'phone' => $data['link_tel'],
  262. 'label' => $data['label'],
  263. 'introduction' => $data['introduction'],
  264. 'explain' => $data['explain'],
  265. 'add_time' => time()
  266. ];
  267. $res = self::set($array);
  268. return $res;
  269. }
  270. }