Sales.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\expand\controller;
  3. use app\common\service\HelperService;
  4. use think\Validate;
  5. /**
  6. * 销售数据
  7. * Class Sales
  8. * @package app\expand\controller
  9. */
  10. class Sales extends BaseAuth
  11. {
  12. private $_Account = null;
  13. private $_redisKey = 'sales_list';
  14. public function __construct(){
  15. parent::__construct();
  16. $this->_Account = $this->getKey($this->_apiCode);
  17. //验证是否具有访问这个接口的权限
  18. if(!isset($this->_Account['Sales'])){
  19. HelperService::returnJson(['code'=>400,'msg'=>'sales interface unauthorized access','data'=>[]]);
  20. }
  21. }
  22. /**
  23. * 入队列
  24. */
  25. public function pushSales(){
  26. $params = $this->_params;
  27. $rule = [
  28. 'company_no|集团编号'=>'require|max:100',
  29. 'store_no|门店编号'=>'require|max:100',
  30. 'sales_no|销售单号'=>'require|max:100',
  31. 'sales_detail|销售明细'=>'require|array',
  32. 'other|其他备注信息'=>'array'
  33. ];
  34. $validate = new Validate($rule);
  35. if(!$validate->check($params)){
  36. HelperService::returnJson(['code'=>400,'msg'=>$validate->getError(),'data'=>[]]);
  37. }
  38. if(!empty($params['detail'])){
  39. foreach($params['detail'] as $detail){
  40. if(!isset($detail['product_no']) || !isset($detail['sales_num']) || !isset($detail['is_refund'])){
  41. HelperService::returnJson(['code'=>400,'msg'=>"销售明细不合法",'data'=>[]]);
  42. }
  43. }
  44. }
  45. $this->connectionRedis();
  46. $this->_redisClient->lpush($this->_redisKey, json_encode($params));
  47. HelperService::returnJson(['code'=>200,'msg'=>'success','data'=>[]]);
  48. }
  49. }