GoodsOrder.php-20230915 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. namespace app\admin\controller\life;
  3. use app\admin\controller\BaseController;
  4. use app\admin\server\life\GoodsOrderServer;
  5. use app\admin\model\GoodsOrder as GoodsOrderModel;
  6. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  7. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  8. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  9. use app\admin\model\LifeGoods;
  10. use app\admin\model\User;
  11. use support\Db;
  12. class GoodsOrder extends BaseController
  13. {
  14. /**
  15. * Notes:获取订单列表
  16. * @return \support\Response
  17. * User: ZQ
  18. * Date: 2022/10/13
  19. */
  20. public function getOrderList()
  21. {
  22. [$page, $limit] = $this->getPage();
  23. $keywords = $this->request->get('keywords');
  24. $order_type_model = $this->request->get('order_type_model',1);
  25. $result = GoodsOrderServer::getOrderList($page, $limit,$keywords,$order_type_model);
  26. return json_success($result, '成功');
  27. }
  28. /**
  29. * Notes:订单详情
  30. * @return \support\Response
  31. * User: ZQ
  32. * Date: 2022/10/13
  33. */
  34. public function orderInfo()
  35. {
  36. $order_id = $this->request->get('order_id');
  37. $result = GoodsOrderServer::orderInfo($order_id);
  38. if ($result){
  39. return json_success($result, '获取成功');
  40. }else{
  41. throw new \Exception('获取失败!');
  42. }
  43. }
  44. /**
  45. * Notes:发货
  46. * @return \support\Response
  47. * User: YCP
  48. * Date: 2023/5/12
  49. */
  50. public function orderDelivery()
  51. {
  52. $params = $this->request->post();
  53. $admin_id = $this->request->admin_id;
  54. $result = GoodsOrderServer::orderDelivery($params,$admin_id);
  55. if ($result){
  56. return json_success($result, '获取成功');
  57. }else{
  58. throw new \Exception('获取失败!');
  59. }
  60. }
  61. /**
  62. * Notes:修改订单支付状态
  63. * @return \support\Response
  64. * User: YCP
  65. * Date: 2022/11/28
  66. */
  67. public function updatePayStatus()
  68. {
  69. $order_id = $this->request->post('order_id');
  70. $order_pay_status = $this->request->post('order_pay_status');
  71. if(!$order_id){
  72. throw new \Exception('订单ID不能为空');
  73. }
  74. $result = GoodsOrderServer::updatePayStatus($order_id, $order_pay_status);
  75. return json_success($result, '修改成功');
  76. }
  77. /**
  78. * Notes:导出订单
  79. * @return \support\Response
  80. * User: YCP
  81. * Date: 2023/8/10
  82. */
  83. public function orderExport()
  84. {
  85. $spreadsheet = new Spreadsheet();
  86. $sheet = $spreadsheet->getActiveSheet();
  87. // 居中对齐
  88. $styleArray = [
  89. 'alignment' => [
  90. 'horizontal' => Alignment::HORIZONTAL_CENTER, //水平居中
  91. 'vertical' => Alignment::VERTICAL_CENTER, //垂直居中
  92. ],
  93. ];
  94. $sheet->getDefaultColumnDimension()->setWidth(20);// 列宽
  95. //自动计算列宽
  96. $sheet->getColumnDimension('A')->setAutoSize(true);
  97. $sheet->getDefaultRowDimension()->setRowHeight(20);// 行高
  98. // 标题
  99. $tabletitle = '悦享家待发货订单表(备注:相同订单号请填写相同的快递单号)';
  100. $sheet->mergeCells('A1:K1');
  101. $sheet->getRowDimension('1')->setRowHeight(40);// 行高
  102. $sheet->getStyle('A1')->applyFromArray($styleArray);
  103. $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
  104. $sheet->setCellValue('A1', $tabletitle);
  105. $sheet->getStyle('A2:K2')->getFont()->setBold(true)->setSize(12);
  106. $sheet->setCellValue('A2','订单号');
  107. $sheet->setCellValue('B2','下单时间');
  108. $sheet->setCellValue('C2','收货人');
  109. $sheet->setCellValue('D2','电话');
  110. $sheet->setCellValue('E2','地址');
  111. $sheet->setCellValue('F2','商品');
  112. $sheet->setCellValue('G2','规格');
  113. $sheet->setCellValue('H2','数量');
  114. $sheet->setCellValue('I2','备注');
  115. $sheet->setCellValue('J2','快递单号');
  116. $sheet->setCellValue('K2','快递公司');
  117. $data = GoodsOrderModel::select(['life_market_order.order_dno','life_market_order.order_address_nickname','life_market_order.order_address_mobile','life_market_order.order_address','life_market_order.order_remke','life_market_order.order_create_time','life_market_order_detail.detail_goods_name','life_market_order_detail.detail_goods_num','life_market_goods.goods_attr'])
  118. ->RightJoin('life_market_order_detail','detail_order_id','=','life_market_order.order_id')
  119. ->leftJoin('life_market_goods','goods_id','=','life_market_order_detail.detail_goods_id')
  120. ->where(['order_pay_status'=>1,'order_status'=>1])
  121. ->orderBy('order_create_time','DESC')
  122. ->get()->toArray();
  123. //return json_success($data, '修改成功');
  124. $sort = 0;
  125. foreach ($data as $v){
  126. $sheet->setCellValue('A' . ($sort + 3), $v['order_dno']);
  127. $sheet->setCellValue('B' . ($sort + 3), $v['order_create_time']);
  128. $sheet->setCellValue('C' . ($sort + 3), $v['order_address_nickname']);
  129. $sheet->setCellValue('D' . ($sort + 3), $v['order_address_mobile']);
  130. $sheet->setCellValue('E' . ($sort + 3), $v['order_address']);
  131. $sheet->setCellValue('F' . ($sort + 3), $v['detail_goods_name']);
  132. $sheet->setCellValue('G' . ($sort + 3), $v['goods_attr']);
  133. $sheet->setCellValue('H' . ($sort + 3), $v['detail_goods_num']);
  134. $sheet->setCellValue('I' . ($sort + 3), $v['order_remke']);
  135. $sort++;
  136. }
  137. // 工作簿标题
  138. $sheettitle = '悦享家待发货订单表';
  139. $sheet->setTitle($sheettitle);
  140. // 文件名
  141. $filename='悦享集市待发货订单_'.date('Y-m-dHis');
  142. $writer = new Xlsx($spreadsheet);
  143. $file_path = public_path().'/'.$filename.'.xlsx';
  144. // 保存文件到 public 下
  145. $writer->save($file_path);
  146. // 下载文件
  147. return response()->download($file_path, $filename.'.xlsx');
  148. }
  149. /**
  150. * Notes:导入发货订单
  151. * @return \support\Response
  152. * @throws \Exception
  153. * User: YCP
  154. * Date: 2023/8/11
  155. */
  156. public function orderImport()
  157. {
  158. $excel_address = $this->request->get('excel_address');//文件地址;
  159. $admin_id = $this->request->admin_id;
  160. require_once 'vendor/phpoffice/phpexcel/Classes/PHPExcel.php';
  161. require_once 'vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php';
  162. $objPHPExcel = \PHPExcel_IOFactory::load($excel_address);
  163. // 逐行读取 sheet 内的内容(常用)
  164. foreach ($objPHPExcel->getworksheetiterator() as $sheet){ //循环sheet
  165. foreach ($sheet->getrowiterator() as $row){ //循环row
  166. if ($row->getrowindex() < 3){ // 默认从第二行开始
  167. continue;
  168. }
  169. foreach ($row->getcelliterator() as $cell){ //循环cell
  170. $data[] = $cell->getvalue();
  171. }
  172. if(!empty($data)){
  173. $order_dno = $data[0];
  174. $order = GoodsOrderModel::where(['order_dno' => $order_dno])->first();
  175. if($order['order_pay_status'] == 1 && $order['order_status'] == 1){
  176. $params['order_express_no'] = $data[9];
  177. $params['order_express_company'] = $data[10];
  178. $params['order_status'] = 2;
  179. $params['order_deliver_time'] = time();
  180. $result = GoodsOrderModel::where(['order_dno' => $order_dno])->update($params);
  181. if (!empty($result)){
  182. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '导入订单物流信息-编号: ' . $result;
  183. plog('user-order-update', '悦享集市-导入物流信息', $msg);
  184. }
  185. }
  186. unset($data);
  187. }else{
  188. throw new \Exception('读取失败');
  189. }
  190. }
  191. }
  192. return json_success('', '导入成功');
  193. }
  194. /**
  195. * Notes:数据统计
  196. * @return \support\Response
  197. * User: YCP
  198. * Date: 2023/8/21
  199. */
  200. public function dataStatistics()
  201. {
  202. //健康超市
  203. $data['market_goods_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_shop_id'=>1])->whereNotIn('goods_category_id',[300])->count();//产品总数
  204. $data['market_goods_on_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_status'=>1,'goods_shop_id'=>1])->whereNotIn('goods_category_id',[300])->count();//已上架产品数
  205. $data['market_goods_off_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_status'=>2,'goods_shop_id'=>1])->whereNotIn('goods_category_id',[300])->count();//已上架产品数
  206. $data['market_goods_sell_count'] = GoodsOrderModel::RightJoin('life_market_order_detail','detail_order_id','=','life_market_order.order_id')
  207. ->where(['order_pay_status'=>1,'order_type_model'=>1])
  208. ->sum('life_market_order_detail.detail_goods_num');
  209. $data['market_order_count'] = GoodsOrderModel::where(['order_type_model'=>1])->count();
  210. $data['market_order_status_count'] = GoodsOrderModel::select(DB::raw('count(*) as count, order_status'))
  211. ->where(['order_pay_status'=>1,'order_type_model'=>1])
  212. ->groupBy('order_status')
  213. ->get();
  214. $data['market_order_pay_status_count'] = GoodsOrderModel::select(DB::raw('count(*) as count, order_pay_status'))
  215. ->where(['order_type_model'=>1])
  216. //->where('order_pay_status','!=',1)
  217. ->groupBy('order_pay_status')
  218. ->get();
  219. //中医馆
  220. $data['zhongyi_goods_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_shop_id'=>32])->count();//产品总数
  221. $data['zhongyi_goods_on_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_status'=>1,'goods_shop_id'=>32])->count();//已上架产品数
  222. $data['zhongyi_goods_off_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_status'=>2,'goods_shop_id'=>32])->count();//已上架产品数
  223. $data['zhongyi_order_count'] = GoodsOrderModel::where(['order_type_model'=>3])->count();
  224. $data['zhongyi_order_status_count'] = GoodsOrderModel::select(DB::raw('count(*) as count, order_status'))
  225. ->where(['order_pay_status'=>1,'order_type_model'=>3])
  226. ->groupBy('order_status')
  227. ->get();
  228. $data['zhongyi_order_pay_status_count'] = GoodsOrderModel::select(DB::raw('count(*) as count, order_pay_status'))
  229. ->where(['order_type_model'=>3])
  230. //->where('order_pay_status','!=',1)
  231. ->groupBy('order_pay_status')
  232. ->get();
  233. //会员
  234. $data['user_type_count'] = User::select(DB::raw('count(*) as count, user_type'))
  235. ->groupBy('user_type')
  236. ->get();
  237. return json_success($data,'成功');
  238. }
  239. }