Pendorder.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\cashier\storeapi\controller;
  13. use addon\cashier\model\order\PendOrder as PendOrderModel;
  14. use app\storeapi\controller\BaseStoreApi;
  15. class Pendorder extends BaseStoreApi
  16. {
  17. public function add()
  18. {
  19. $goods = $this->params[ 'goods' ] ?? '[]';
  20. $discount = $this->params[ 'discount' ] ?? '{}';
  21. $data = [
  22. 'site_id' => $this->site_id,
  23. 'member_id' => $this->params[ 'member_id' ] ?? 0,
  24. 'store_id' => $this->store_id,
  25. 'goods' => json_decode($goods, true),
  26. 'discount_moeny' => $this->params[ 'discount_moeny' ] ?? 0,
  27. 'discount' => $discount,
  28. 'remark' => $this->params[ 'remark' ] ?? ''
  29. ];
  30. $res = ( new PendOrderModel() )->add($data);
  31. return $this->response($res);
  32. }
  33. public function edit()
  34. {
  35. $goods = $this->params[ 'goods' ] ?? '[]';
  36. $discount = $this->params[ 'discount' ] ?? '{}';
  37. $data = [
  38. 'site_id' => $this->site_id,
  39. 'order_id' => $this->params[ 'order_id' ],
  40. 'member_id' => $this->params[ 'member_id' ] ?? 0,
  41. 'store_id' => $this->store_id,
  42. 'goods' => json_decode($goods, true),
  43. 'discount_moeny' => $this->params[ 'discount_moeny' ] ?? 0,
  44. 'discount' => $discount,
  45. 'remark' => $this->params[ 'remark' ] ?? ''
  46. ];
  47. $res = ( new PendOrderModel() )->edit($data);
  48. return $this->response($res);
  49. }
  50. public function page()
  51. {
  52. $page_index = $this->params[ 'page' ] ?? 1;
  53. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  54. $condition = [
  55. [ 'o.site_id', '=', $this->site_id ],
  56. [ 'o.store_id', '=', $this->store_id ]
  57. ];
  58. $model = new PendOrderModel();
  59. $data = $model->getOrderPageList($condition, 'o.*,m.nickname', 'o.create_time desc', $page_index, $page_size, 'o', [ [ 'member m', 'm.member_id = o.member_id', 'left' ] ]);
  60. if (!empty($data[ 'data' ][ 'list' ])) {
  61. $field = 'og.*, g.goods_name, gs.spec_name, g.goods_image';
  62. foreach ($data[ 'data' ][ 'list' ] as $k => $v) {
  63. $list = $model->getOrderGoodsList([ [ 'og.order_id', '=', $v[ 'order_id' ] ] ], $field, '', 'og', [
  64. [ 'goods g', 'g.goods_id = og.goods_id', 'left' ],
  65. [ 'goods_sku gs', 'gs.sku_id = og.sku_id', 'left' ]
  66. ])[ 'data' ];
  67. $data[ 'data' ][ 'list' ][ $k ][ 'order_goods' ] = $list;
  68. }
  69. }
  70. return $this->response($data);
  71. }
  72. public function delete()
  73. {
  74. $order_id = $this->params[ 'order_id' ];
  75. $res = ( new PendOrderModel() )->delete([
  76. 'site_id' => $this->site_id,
  77. 'store_id' => $this->store_id,
  78. 'order_id' => $order_id
  79. ]);
  80. return $this->response($res);
  81. }
  82. public function updateRemark()
  83. {
  84. $order_id = $this->params[ 'order_id' ];
  85. $remark = $this->params[ 'remark' ];
  86. $res = ( new PendOrderModel() )->update([ 'remark' => $remark ], [
  87. [ 'site_id', '=', $this->site_id ],
  88. [ 'store_id', '=', $this->store_id ],
  89. [ 'order_id', '=', $order_id ]
  90. ]);
  91. return $this->response($res);
  92. }
  93. }