GoodsOrder.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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:M1');
  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:M2')->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. $sheet->setCellValue('L2','快递单号');
  118. $sheet->setCellValue('M2','快递公司');
  119. $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_order_detail.detail_goods_price','life_market_goods.goods_attr'])
  120. ->RightJoin('life_market_order_detail','detail_order_id','=','life_market_order.order_id')
  121. ->leftJoin('life_market_goods','goods_id','=','life_market_order_detail.detail_goods_id')
  122. ->where(['order_pay_status'=>1,'order_status'=>1])
  123. ->orderBy('order_create_time','DESC')
  124. ->get()->toArray();
  125. //return json_success($data, '修改成功');
  126. $sort = 0;
  127. foreach ($data as $v){
  128. $sheet->setCellValue('A' . ($sort + 3), $v['order_dno']);
  129. $sheet->setCellValue('B' . ($sort + 3), $v['order_create_time']);
  130. $sheet->setCellValue('C' . ($sort + 3), $v['order_address_nickname']);
  131. $sheet->setCellValue('D' . ($sort + 3), $v['order_address_mobile']);
  132. $sheet->setCellValue('E' . ($sort + 3), $v['order_address']);
  133. $sheet->setCellValue('F' . ($sort + 3), $v['detail_goods_name']);
  134. $sheet->setCellValue('G' . ($sort + 3), $v['goods_attr']);
  135. $sheet->setCellValue('H' . ($sort + 3), $v['detail_goods_num']);
  136. $sheet->setCellValue('I' . ($sort + 3), $v['detail_goods_price']);
  137. $sheet->setCellValue('J' . ($sort + 3), round($v['detail_goods_num'] * $v['detail_goods_price'], 2));
  138. $sheet->setCellValue('K' . ($sort + 3), $v['order_remke']);
  139. $sort++;
  140. }
  141. // 工作簿标题
  142. $sheettitle = '悦享家待发货订单表';
  143. $sheet->setTitle($sheettitle);
  144. // 文件名
  145. $filename='悦享集市待发货订单_'.date('Y-m-dHis');
  146. $writer = new Xlsx($spreadsheet);
  147. $file_path = public_path().'/'.$filename.'.xlsx';
  148. // 保存文件到 public 下
  149. $writer->save($file_path);
  150. // 下载文件
  151. return response()->download($file_path, $filename.'.xlsx');
  152. }
  153. /**
  154. * Notes:导入发货订单
  155. * @return \support\Response
  156. * @throws \Exception
  157. * User: YCP
  158. * Date: 2023/8/11
  159. */
  160. public function orderImport()
  161. {
  162. $excel_address = $this->request->get('excel_address');//文件地址;
  163. $admin_id = $this->request->admin_id;
  164. require_once 'vendor/phpoffice/phpexcel/Classes/PHPExcel.php';
  165. require_once 'vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php';
  166. $objPHPExcel = \PHPExcel_IOFactory::load($excel_address);
  167. // 逐行读取 sheet 内的内容(常用)
  168. foreach ($objPHPExcel->getworksheetiterator() as $sheet){ //循环sheet
  169. foreach ($sheet->getrowiterator() as $row){ //循环row
  170. if ($row->getrowindex() < 3){ // 默认从第二行开始
  171. continue;
  172. }
  173. foreach ($row->getcelliterator() as $cell){ //循环cell
  174. $data[] = $cell->getvalue();
  175. }
  176. if(!empty($data)){
  177. $order_dno = $data[0];
  178. $order = GoodsOrderModel::where(['order_dno' => $order_dno])->first();
  179. if($order['order_pay_status'] == 1 && $order['order_status'] == 1){
  180. $params['order_express_no'] = $data[11];
  181. $params['order_express_company'] = $data[12];
  182. $params['order_status'] = 2;
  183. $params['order_deliver_time'] = time();
  184. $result = GoodsOrderModel::where(['order_dno' => $order_dno])->update($params);
  185. if (!empty($result)){
  186. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '导入订单物流信息-编号: ' . $result;
  187. plog('user-order-update', '悦享集市-导入物流信息', $msg);
  188. }
  189. }
  190. unset($data);
  191. }else{
  192. throw new \Exception('读取失败');
  193. }
  194. }
  195. }
  196. return json_success('', '导入成功');
  197. }
  198. /**
  199. * Notes:数据统计
  200. * @return \support\Response
  201. * User: YCP
  202. * Date: 2023/8/21
  203. */
  204. public function dataStatistics()
  205. {
  206. //健康超市
  207. $data['market_goods_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_shop_id'=>1])->whereNotIn('goods_category_id',[300])->count();//产品总数
  208. $data['market_goods_on_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_status'=>1,'goods_shop_id'=>1])->whereNotIn('goods_category_id',[300])->count();//已上架产品数
  209. $data['market_goods_off_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_status'=>2,'goods_shop_id'=>1])->whereNotIn('goods_category_id',[300])->count();//已上架产品数
  210. $data['market_goods_sell_count'] = GoodsOrderModel::RightJoin('life_market_order_detail','detail_order_id','=','life_market_order.order_id')
  211. ->where(['order_pay_status'=>1,'order_type_model'=>1])
  212. ->sum('life_market_order_detail.detail_goods_num');
  213. $data['market_order_count'] = GoodsOrderModel::where(['order_type_model'=>1])->count();
  214. $data['market_order_status_count'] = GoodsOrderModel::select(DB::raw('count(*) as count, order_status'))
  215. ->where(['order_pay_status'=>1,'order_type_model'=>1])
  216. ->groupBy('order_status')
  217. ->get();
  218. $data['market_order_pay_status_count'] = GoodsOrderModel::select(DB::raw('count(*) as count, order_pay_status'))
  219. ->where(['order_type_model'=>1])
  220. //->where('order_pay_status','!=',1)
  221. ->groupBy('order_pay_status')
  222. ->get();
  223. //中医馆
  224. $data['zhongyi_goods_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_shop_id'=>32])->count();//产品总数
  225. $data['zhongyi_goods_on_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_status'=>1,'goods_shop_id'=>32])->count();//已上架产品数
  226. $data['zhongyi_goods_off_count'] = LifeGoods::where(['goods_is_del'=>0,'goods_status'=>2,'goods_shop_id'=>32])->count();//已上架产品数
  227. $data['zhongyi_order_count'] = GoodsOrderModel::where(['order_type_model'=>3])->count();
  228. $data['zhongyi_order_status_count'] = GoodsOrderModel::select(DB::raw('count(*) as count, order_status'))
  229. ->where(['order_pay_status'=>1,'order_type_model'=>3])
  230. ->groupBy('order_status')
  231. ->get();
  232. $data['zhongyi_order_pay_status_count'] = GoodsOrderModel::select(DB::raw('count(*) as count, order_pay_status'))
  233. ->where(['order_type_model'=>3])
  234. //->where('order_pay_status','!=',1)
  235. ->groupBy('order_pay_status')
  236. ->get();
  237. //会员
  238. $data['user_type_count'] = User::select(DB::raw('count(*) as count, user_type'))
  239. ->groupBy('user_type')
  240. ->get();
  241. return json_success($data,'成功');
  242. }
  243. }