Lecturer.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\special;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\admin\model\order\StoreOrder as StoreOrderModel;
  15. use app\admin\model\special\Special;
  16. /**
  17. * Class Lecturer 讲师
  18. * @package app\admin\model\special
  19. */
  20. class Lecturer extends ModelBasic
  21. {
  22. use ModelTrait;
  23. //设置where条件
  24. public static function setWhere($where, $alirs = '', $model = null)
  25. {
  26. $model = $model === null ? new self() : $model;
  27. $model = $alirs === '' ? $model->alias($alirs) : $model;
  28. $alirs = $alirs === '' ? $alirs : $alirs . '.';
  29. $model = $model->where("{$alirs}is_del", 0);
  30. if ($where['is_show'] !== '') $model = $model->where("{$alirs}is_show", $where['is_show']);
  31. if ($where['title']) $model = $model->where("{$alirs}lecturer_name", 'LIKE', "%$where[title]%");
  32. $model = $model->order("{$alirs}sort desc");
  33. return $model;
  34. }
  35. /**讲师列表
  36. * @param $where
  37. * @return array
  38. * @throws \think\Exception
  39. */
  40. public static function getLecturerList($where)
  41. {
  42. $data = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  43. $data = count($data) ? $data->toArray() : [];
  44. $count = self::setWhere($where)->count();
  45. return compact('data', 'count');
  46. }
  47. /**
  48. * 删除讲师
  49. * @param $id
  50. * @return bool|int
  51. * @throws \think\exception\DbException
  52. */
  53. public static function delLecturer($id)
  54. {
  55. $lecturer = self::get($id);
  56. if (!$lecturer) return self::setErrorInfo('删除的数据不存在');
  57. $count=Special::where('is_del',0)->where('lecturer_id',$id)->count();
  58. if($count){
  59. Special::where('is_del',0)->where('lecturer_id',$id)->update(['lecturer_id'=>0]);
  60. }
  61. return self::where('id',$id)->update(['is_del'=>1]);
  62. }
  63. /**讲师课程订单
  64. * @param $lecturer_id
  65. */
  66. public static function lecturerOrderList($where)
  67. {
  68. $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');
  69. $data = ($data = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
  70. foreach ($data as $key=>&$value){
  71. if ($value['paid'] == 0 && $value['status'] == 0) {
  72. $value['status_name'] = '未支付';
  73. } else if ($value['paid'] == 1 && $value['status'] == 0 && $value['refund_status'] == 0 && $value['type'] != 2) {
  74. $value['status_name'] = '已支付';
  75. }
  76. if($value['nickname']){
  77. $value['nickname']=$value['nickname'].'/'.$value['uid'];
  78. }else{
  79. $value['nickname']='用户被删除/'.$value['uid'];
  80. }
  81. if ($value['paid'] == 1) {
  82. switch ($value['pay_type']) {
  83. case 'weixin':
  84. $value['pay_type_name'] = '微信支付';
  85. break;
  86. case 'yue':
  87. $value['pay_type_name'] = '余额支付';
  88. break;
  89. case 'zhifubao':
  90. $value['pay_type_name'] = '支付宝支付';
  91. break;
  92. default:
  93. $value['pay_type_name'] = '其他支付';
  94. break;
  95. }
  96. } else {
  97. switch ($value['pay_type']) {
  98. default:
  99. $value['pay_type_name'] = '未支付';
  100. break;
  101. }
  102. }
  103. }
  104. $count = self::getOrderWhere($where)->count();
  105. return compact('count', 'data');
  106. }
  107. /**条件处理
  108. * @param $where
  109. * @return StoreOrderModel
  110. */
  111. public static function getOrderWhere($where)
  112. {
  113. $model=StoreOrderModel::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT')
  114. ->join('Special s','a.cart_id=s.id')
  115. ->where('a.type',0)->where('a.paid',1);
  116. if($where['lecturer_id']){
  117. $model=$model->where('s.lecturer_id',$where['lecturer_id']);
  118. }
  119. if ($where['data'] !== '') {
  120. $model = self::getModelTime($where, $model, 'a.add_time');
  121. }
  122. $model = $model->order('a.id desc');
  123. return $model;
  124. }
  125. /**
  126. * 处理订单金额
  127. * @param $where
  128. * @return array
  129. */
  130. public static function getOrderPrice($where)
  131. {
  132. $price = array();
  133. $price['pay_price'] = 0;//支付金额
  134. $price['pay_price_wx'] = 0;//微信支付金额
  135. $price['pay_price_yue'] = 0;//余额支付金额
  136. $price['pay_price_zhifubao'] = 0;//支付宝支付金额
  137. $list = self::getOrderWhere($where)->field([
  138. 'sum(a.total_num) as total_num',
  139. 'sum(a.pay_price) as pay_price',
  140. ])->find()->toArray();
  141. $price['total_num'] = $list['total_num'];//商品总数
  142. $price['pay_price'] = $list['pay_price'];//支付金额
  143. $list = self::getOrderWhere($where)->field('sum(a.pay_price) as pay_price,a.pay_type')->group('a.pay_type')->select()->toArray();
  144. foreach ($list as $v) {
  145. if ($v['pay_type'] == 'weixin') {
  146. $price['pay_price_wx'] = $v['pay_price'];
  147. } elseif ($v['pay_type'] == 'yue') {
  148. $price['pay_price_yue'] = $v['pay_price'];
  149. } elseif ($v['pay_type'] == 'zhifubao') {
  150. $price['pay_price_zhifubao'] = $v['pay_price'];
  151. } else {
  152. $price['pay_price_other'] = $v['pay_price'];
  153. }
  154. }
  155. $price['order_sum'] =self::getOrderWhere($where)->count();
  156. return $price;
  157. }
  158. public static function getBadge($where)
  159. {
  160. $price = self::getOrderPrice($where);
  161. return [
  162. [
  163. 'name' => '订单数量',
  164. 'field' => '件',
  165. 'count' => $price['order_sum'],
  166. 'background_color' => 'layui-bg-blue',
  167. 'col' => 4
  168. ],
  169. [
  170. 'name' => '售出课程',
  171. 'field' => '件',
  172. 'count' => $price['total_num'],
  173. 'background_color' => 'layui-bg-blue',
  174. 'col' => 4
  175. ],
  176. [
  177. 'name' => '订单金额',
  178. 'field' => '元',
  179. 'count' => $price['pay_price'],
  180. 'background_color' => 'layui-bg-blue',
  181. 'col' => 4
  182. ],
  183. [
  184. 'name' => '微信支付金额',
  185. 'field' => '元',
  186. 'count' => $price['pay_price_wx'],
  187. 'background_color' => 'layui-bg-blue',
  188. 'col' => 4
  189. ],
  190. [
  191. 'name' => '余额支付金额',
  192. 'field' => '元',
  193. 'count' => $price['pay_price_yue'],
  194. 'background_color' => 'layui-bg-blue',
  195. 'col' => 4
  196. ],
  197. [
  198. 'name' => '支付宝支付金额',
  199. 'field' => '元',
  200. 'count' => $price['pay_price_zhifubao'],
  201. 'background_color' => 'layui-bg-blue',
  202. 'col' => 4
  203. ]
  204. ];
  205. }
  206. }