Origin.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\admin\model\SaleOriginChange;use think\App;use think\facade\Cache;use think\facade\Validate;use think\Request;
  5. class Origin extends Base
  6. {
  7. protected $model=null;
  8. public $white=["*"];
  9. public function __construct(App $app) {
  10. parent::__construct($app);
  11. $this->model=new SaleOriginChange();
  12. }
  13. /** 成本修改列表
  14. * @return \think\response\Json|void
  15. * @throws \think\db\exception\DbException
  16. */
  17. public function list(){
  18. $param =$this->request->only(['orderCode'=>'','companyNo'=>'',"size"=>15,"page"=>1],'post','trim');
  19. $where=[];
  20. $param["orderCode"]==""?: $where[]=["sale_origin_change.orderCode","like","%{$param["orderCode"]}%"];
  21. $param["companyNo"]==""?: $where[]=["orderInfo.supplierNo","=",$param["companyNo"]];
  22. $list = $this->model
  23. ->withJoin(["orderInfo"],"left")
  24. ->order("id","desc")
  25. ->where($where)
  26. ->paginate(["list_rows"=>$param["size"],"page"=>$param["page"]]);
  27. return app_show(0,"获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  28. }
  29. /** 新建
  30. * @return \think\response\Json|void
  31. */
  32. public function create(){
  33. $param =$this->request->only(["orderCode"=>"","change_fee"=>"","remark"=>""],"post","trim");
  34. $valid =Validate::rule(["orderCode|订单编号"=>"require|max:255","change_fee|成本修改金额"=>"require"]);
  35. if($valid->check($param)==false)return error_show(1004,$valid->getError());
  36. $orderInfo = \app\admin\model\Sale::where("orderCode",$param['orderCode'])->findOrEmpty();
  37. if($orderInfo->isEmpty())return error_show(1004,"订单数据未找到");
  38. $data=[
  39. "orderCode"=>$orderInfo->orderCode,
  40. "origin_price"=>bcadd(bcmul($orderInfo->origin_price,bcsub($orderInfo->good_num,$orderInfo->th_num),6),$orderInfo->post_fee,6),
  41. "change_price"=>bcadd(bcmul($orderInfo->origin_price,bcsub($orderInfo->good_num,$orderInfo->th_num),6),bcadd($orderInfo->post_fee,$param['change_fee'],6),6),
  42. "change_fee"=>$param['change_fee'],
  43. "apply_id"=>$this->uid,
  44. "apply_name"=>$this->uname,
  45. "remark"=>$param["remark"]
  46. ];
  47. $orderInfo->post_fee = bcadd($orderInfo->post_fee,$param['change_fee'],6);
  48. $up = $orderInfo->save();
  49. if($up==false)return error_show(1004,'订单数据更新失败');
  50. $create =SaleOriginChange::create($data);
  51. return app_show(0,"成本修改成功");
  52. }
  53. /** 详情
  54. * @return \think\response\Json|void
  55. */
  56. public function info(){
  57. $id =$this->request->post("id");
  58. $info =$this->model->with(["order_info"])->findOrEmpty($id);
  59. if($info->isEmpty())return error_show(1004,'数据未找到');
  60. return app_show(0,'数据查询成功',$info);
  61. }
  62. }