AuctionOrder.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. namespace app\admin\controller\auction;
  3. use app\admin\controller\AuthController;
  4. use app\admin\controller\Union;
  5. use app\admin\model\user\User;
  6. use app\admin\model\user\UserBill;
  7. use app\models\auction\AuctionProduct;
  8. use app\models\auction\AuctionTime;
  9. use crmeb\services\{ExpressService,
  10. JsonService,
  11. MiniProgramService,
  12. upload\Upload,
  13. WechatService,
  14. FormBuilder as Form,
  15. CacheService,
  16. UtilService as Util,
  17. JsonService as Json};
  18. use app\admin\model\system\{
  19. SystemAttachment as SystemAttachmentModel, SystemAttachmentCategory as Category
  20. };
  21. use app\admin\model\auction\AuctionOrder as model;
  22. use think\facade\Db;
  23. use think\facade\Route as Url;
  24. /**
  25. * 竞拍管理
  26. * Class StoreOrder
  27. * @package app\admin\controller\store
  28. */
  29. class AuctionOrder extends AuthController
  30. {
  31. public function index()
  32. {
  33. $list = \app\admin\model\auction\Auction::select();
  34. $gu = \app\admin\model\auction\AuctionGu::select();
  35. $this->assign([
  36. 'year' => get_month(),
  37. 'auction'=> $list,
  38. 'gu' => $gu
  39. ]);
  40. return $this->fetch();
  41. }
  42. /**
  43. * 获取列表
  44. * @return void
  45. */
  46. public function list()
  47. {
  48. $where = Util::getMore([
  49. ['is_show', ''],
  50. ['page', 1],
  51. ['limit', 20],
  52. ['auction_id', ''],
  53. ['store_name', ''],
  54. ['data', ''],
  55. ['status', ''],
  56. ['gu_id', ''],
  57. ['product_name'],
  58. ['excel', 0],
  59. ['is_gs', ''],
  60. ['uid']
  61. ]);
  62. if ($this->adminInfo['roles'] == 8){
  63. if ($this->adminInfo['uid']){
  64. $where['uid'] = $this->adminInfo['uid'];
  65. }
  66. }
  67. $data = model::list($where);
  68. foreach ($data['data'] as $key => $val){
  69. if ($data['data'][$key]['uid'] == 0) $data['data'][$key]['nickname'] = '管理';
  70. }
  71. return Json::successlayui($data);
  72. }
  73. public function auction_list()
  74. {
  75. $list = model::select()->toArray();
  76. Json::successful($list);
  77. }
  78. /**
  79. * 显示创建资源表单页.
  80. *
  81. * @return \think\Response
  82. */
  83. public function create($id = 0)
  84. {
  85. $data = \app\admin\model\auction\Auction::select()->toArray();
  86. $this->assign(['id' => $id, 'list' => $data]);
  87. return $this->fetch();
  88. }
  89. /**
  90. * 添加
  91. * @param $id
  92. * @return void
  93. */
  94. public function save($id)
  95. {
  96. $data = Util::postMore([
  97. 'name',
  98. 'is_show',
  99. 'image',
  100. 'price',
  101. 'deduct',
  102. 'rise',
  103. 'info',
  104. 'sort',
  105. 'auction_id'
  106. ]);
  107. $model = new model();
  108. $res = $model->save($data);
  109. if ($res){
  110. return Json::success('添加成功!');
  111. }else{
  112. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  113. }
  114. }
  115. /**
  116. * 删除
  117. * @param $id
  118. * @return void
  119. * @throws \Exception
  120. */
  121. public function delete($id)
  122. {
  123. if (!$id) Json::fail('删除失败');
  124. $res = model::where('id', $id)->delete();
  125. if ($res){
  126. return Json::success('删除成功!');
  127. }else{
  128. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  129. }
  130. }
  131. /**
  132. * 修改状态
  133. * @param $id
  134. * @param $status
  135. * @return void
  136. */
  137. public function set_status($id, $status)
  138. {
  139. if (empty($id)) Json::fail('修改失败');
  140. $res = model::update(['is_show' => $status, 'id' => $id]);
  141. if ($res){
  142. return Json::success('修改成功!');
  143. }else{
  144. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  145. }
  146. }
  147. /**
  148. * 编辑页面
  149. * @param $id
  150. * @return string
  151. * @throws \think\db\exception\DataNotFoundException
  152. * @throws \think\db\exception\DbException
  153. * @throws \think\db\exception\ModelNotFoundException
  154. */
  155. public function edit($id)
  156. {
  157. if (!$id) Json::fail('数据不存在');
  158. $data = \app\admin\model\auction\Auction::select()->toArray();
  159. $this->assign(['id' => $id, 'list' => $data]);
  160. return $this->fetch();
  161. }
  162. public function get_list($id)
  163. {
  164. if (!$id) Json::fail('数据不存在');
  165. $model = new model();
  166. $info = $model->find($id);
  167. return JsonService::successful($info);
  168. }
  169. /**
  170. * 修改
  171. * @param $id
  172. * @return void
  173. */
  174. public function update($id)
  175. {
  176. $data = Util::postMore([
  177. 'id',
  178. 'name',
  179. 'is_show',
  180. 'image',
  181. 'price',
  182. 'deduct',
  183. 'rise',
  184. 'info',
  185. 'sort',
  186. 'auction_id'
  187. ]);
  188. $res = model::update($data);
  189. if ($res){
  190. return Json::success('修改成功!');
  191. }else{
  192. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  193. }
  194. }
  195. /**
  196. * 通过
  197. * @param $id
  198. * @return void
  199. * @throws \think\db\exception\DataNotFoundException
  200. * @throws \think\db\exception\DbException
  201. * @throws \think\db\exception\ModelNotFoundException
  202. */
  203. public function qd($id)
  204. {
  205. if (!$id) return Json::fail('没有数据');
  206. $data = model::find($id);// 订单数据
  207. if($data['status'] < 3 and $data['status'] > 0){
  208. $data['status'] = 3;
  209. try {
  210. Db::startTrans();
  211. $data->save();
  212. $product = AuctionProduct::find($data['product_id']);
  213. if (!$product) return app('json')->fail('数据不存在');
  214. $uid = $product['uid']; // 所属人id
  215. $product['uid'] = $data['uid'];// 商品拥有人更新
  216. $product['add_time'] = time();
  217. $product['order'] = $data['order_id'];
  218. $product['is_show'] = 0;
  219. $res = $product->save();
  220. AuctionTime::where([['product_id', '=', $product['id']]])->delete();
  221. \app\models\auction\AuctionOrder::return($data['id']); // 买家
  222. Db::commit();
  223. return Json::success('修改成功!');
  224. } catch (\Exception $e) {
  225. Db::rollback();
  226. return Json::fail('失败');
  227. }
  228. }
  229. return Json::fail('该订单不能通过');
  230. }
  231. }