CopyTaobao.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\product;
  12. use app\controller\admin\AuthController;
  13. use app\services\product\product\CopyTaobaoServices;
  14. use app\services\serve\ServeServices;
  15. use think\facade\App;
  16. /**
  17. * Class CopyTaobao
  18. * @package app\controller\admin\v1\product
  19. */
  20. class CopyTaobao extends AuthController
  21. {
  22. /**
  23. * CopyTaobao constructor.
  24. * @param App $app
  25. * @param CopyTaobaoServices $services
  26. */
  27. public function __construct(App $app, CopyTaobaoServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 获取复制商品配置信息
  34. * @return mixed
  35. */
  36. public function getConfig()
  37. {
  38. $data = [];
  39. $copy = sys_config('system_product_copy_type', 1);
  40. $data['copy_type'] = $copy;
  41. $data['copy_num'] = 0;
  42. if ($copy == 1) {//一号通
  43. /** @var ServeServices $serverServices */
  44. $serverServices = app()->make(ServeServices::class);
  45. try {
  46. $info = $serverServices->user()->getUser();
  47. } catch (\Throwable $e) {
  48. $info = [];
  49. }
  50. if ($info) {
  51. $data['copy_num'] = $info['copy']['num'] ?? 0;
  52. }
  53. }
  54. return $this->success($data);
  55. }
  56. /**
  57. * 复制商品
  58. * @return mixed
  59. */
  60. public function copyProduct()
  61. {
  62. [$type, $id, $shopid, $url] = $this->request->postMore([
  63. ['type', ''],
  64. ['id', ''],
  65. ['shopid', ''],
  66. ['url', '']
  67. ], true);
  68. $res = $this->services->copyProduct($type, $id, $shopid, $url);
  69. return $this->success($res);
  70. }
  71. /**
  72. * 保存图片保存商品信息
  73. * @return mixed
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. */
  78. public function save_product()
  79. {
  80. $data = $this->request->postMore([
  81. ['cate_id', ''],
  82. ['store_name', ''],
  83. ['store_info', ''],
  84. ['keyword', ''],
  85. ['unit_name', ''],
  86. ['image', ''],
  87. ['slider_image', []],
  88. ['price', 0],
  89. ['ot_price', 0],
  90. ['give_integral', ''],
  91. ['postage', ''],
  92. ['sales', 0],
  93. ['ficti', ''],
  94. ['stock', 0],
  95. ['cost', 0],
  96. ['description_images', []],
  97. ['description', ''],
  98. ['is_show', 0],
  99. ['soure_link', ''],
  100. ['temp_id', 0],
  101. ['spec_type', 0],
  102. ['items', []],
  103. ['attrs', []],
  104. ]);
  105. $this->services->save($data);
  106. return $this->success('生成商品成功');
  107. }
  108. }