You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProductController.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\controller\erp;
  3. use app\jobs\product\ProductSyncErp;
  4. use app\Request;
  5. use crmeb\services\erp\Erp as ErpServices;
  6. use crmeb\services\erp\storage\jushuitan\Product as ProductService;
  7. use think\Response;
  8. /**
  9. * 商品类
  10. * Class ProductController
  11. * @package app\controller\erp
  12. */
  13. class ProductController
  14. {
  15. /*** @var ProductService */
  16. protected $services;
  17. public function __construct(ErpServices $services)
  18. {
  19. $this->services = $services->serviceDriver('product');
  20. }
  21. /**
  22. * 使用spu同步商品
  23. * @param Request $request
  24. * @return mixed
  25. * @throws \Exception
  26. */
  27. public function syncProduct(Request $request)
  28. {
  29. [$spuStr] = $request->getMore([
  30. ['spu_str', ''],
  31. ], true);
  32. if (empty($spuStr)) {
  33. return app('json')->fail('请输入ERP商品SPU');
  34. }
  35. $spuArr = explode(',', $spuStr);
  36. foreach ($spuArr as $item) {
  37. // 获取商品
  38. ProductSyncErp::dispatchDo('productFromErp', [$item]);
  39. }
  40. return app('json')->success('正在同步中,请稍后查看');
  41. }
  42. /**
  43. * 使用sku同步库存
  44. * @param Request $request
  45. * @return mixed
  46. * @throws \Exception
  47. */
  48. public function syncStock(Request $request)
  49. {
  50. [$ids] = $request->getMore([
  51. ['ids', ''],
  52. ], true);
  53. if (empty($ids)) {
  54. return app('json')->fail('请选择商品');
  55. }
  56. $idArr = explode(',', $ids);
  57. $data = array_chunk($idArr, 1);
  58. foreach ($data as $item) {
  59. // 获取库存
  60. ProductSyncErp::dispatchDo('stockFromErp', [$item]);
  61. }
  62. return app('json')->success('正在同步中,请稍后查看');
  63. }
  64. }