Exchange.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\admin\controller\shop;
  3. use app\common\controller\Backend;
  4. use app\admin\model\shop\Goods;
  5. /**
  6. * 积分兑换
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Exchange extends Backend
  11. {
  12. /**
  13. * Exchange模型对象
  14. * @var \app\admin\model\shop\Exchange
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\shop\Exchange;
  21. $this->view->assign("typeList", $this->model->getTypeList());
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. }
  24. //商城商品生成
  25. public function creategoods()
  26. {
  27. $goods_ids = $this->request->post('goods_ids/a');
  28. $score = $this->request->post('score/d');
  29. if (empty($goods_ids)) {
  30. $this->error('缺少参数');
  31. }
  32. if (!$score) {
  33. $this->error('请输入积分');
  34. }
  35. $goods = Goods::where('id', 'IN', $goods_ids)->select();
  36. $data = [];
  37. foreach ($goods as $item) {
  38. $data[] = [
  39. 'type' => 'reality',
  40. 'title' => $item->title,
  41. 'content' => $item->content,
  42. 'description' => $item->description,
  43. 'image' => $item->image,
  44. 'score' => $score,
  45. 'stocks' => $item->stocks
  46. ];
  47. }
  48. $this->model->saveAll($data);
  49. $this->success('复制成功');
  50. }
  51. }