Consult.php 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //咨询单
  9. class Consult extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble =\think\facade\Config::get("noble");
  16. }
  17. public function conlist(){
  18. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  20. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  21. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  22. if ($infoNo !== "") {
  23. $where[] = ['a.infoNo','=',$infoNo];
  24. }
  25. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  26. if ($salesman !== "") {
  27. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  28. $where[]= ["b.salesman",'like',"%$salesman%"];
  29. }
  30. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  31. if ($cpName !== "") {
  32. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  33. $where[]= ["a.good_Name",'like',"%$cpName%"];
  34. }
  35. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  36. if ($khNo !== "") {
  37. // $where['khNo'] = $khNo;
  38. $where[]= ["b.khNo",'like',"%$khNo%"];
  39. }
  40. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  41. if ($companyNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["a.addtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["a.addtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["a.status",'=',$status];
  57. }
  58. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  59. ->count();
  60. $total = ceil($count / $size);
  61. $page = $page >= $total ? $total : $page;
  62. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  63. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->order("a.id desc")->select();
  64. $data=[];
  65. foreach ($list as $value){
  66. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  67. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  68. true):[];
  69. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  70. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  71. $value['khname']="";
  72. if($value['khNo']!==""){
  73. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  74. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  75. }
  76. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  77. $data[]=$value;
  78. }
  79. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  80. }
  81. public function info(){
  82. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  83. if($id==""){
  84. return error_show(1002,"咨询单编号不能为空");
  85. }
  86. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  87. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  88. $fo['can']=$in;
  89. if(empty($fo)){
  90. return error_show(1002,"未找到咨询单编号");
  91. }else{
  92. return app_show(0,"获取成功",$fo);
  93. }
  94. }
  95. public function del(){
  96. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  97. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  98. if($de==false){
  99. return error_show(1002,'咨询单信息未找到');
  100. }
  101. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  102. if($dell){
  103. return error_show(0,"删除成功");
  104. }else
  105. return error_show(1002,"删除失败");
  106. }
  107. public function create(){
  108. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  109. if($is_project===""){
  110. return error_show(1002,"参数is_project不能为空");
  111. }
  112. if($is_project==1){
  113. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  114. if($projectNo===""){
  115. return error_show(1002,"参数projectNo不能为空");
  116. }
  117. }
  118. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  119. if($khNo===""){
  120. return error_show(1002,"参数khNo不能为空");
  121. }
  122. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  123. if($companyNo===""){
  124. return error_show(1002,"参数companyNo不能为空");
  125. }
  126. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  127. if($endtime===""){
  128. return error_show(1002,"参数endtime不能为空");
  129. }
  130. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  131. "";
  132. if($platform_code===""){
  133. return error_show(1002,"参数platform_code不能为空");
  134. }
  135. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  136. if($ladder==""){
  137. return error_show(1005,"参数ladder不能为空");
  138. }
  139. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  140. if($token==''){
  141. return error_show(105,"参数token不能为空");
  142. }
  143. $user =GetUserInfo($token);
  144. if(empty($user)||$user['code']!=0){
  145. return error_show(102,"用户数据不存在");
  146. }
  147. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  148. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  149. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  150. $zxNo=makeNo("ZX");
  151. Db::startTrans();
  152. try{
  153. $data=[
  154. "zxNo"=>$zxNo,
  155. "createrid"=>$createrid,
  156. "creater"=>$creater,
  157. "is_project"=>$is_project,
  158. "projectNo"=>isset($projectNo) ? $projectNo:"",
  159. "khNo"=>$khNo,
  160. "companyNo"=>$companyNo,
  161. "endtime"=>$endtime,
  162. "salesman"=>$creater,
  163. "platform_code"=>$platform_code,
  164. "saleid"=>$createrid,
  165. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  166. "status"=>0,
  167. "is_del"=>0,
  168. "addtime"=>date("Y-m-d H:i:s"),
  169. "updatetime"=>date("Y-m-d H:i:s"),
  170. ];
  171. $zx = Db::name("consult_order")->insert($data);
  172. if($zx){
  173. foreach ($ladder as $value){
  174. $infoNo=makeNo("IF");
  175. $specinfo=[];
  176. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  177. foreach ($value["specinfo"] as $v){
  178. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  179. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  180. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  181. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  182. $specinfo[]=$v;
  183. }
  184. }
  185. $info=[
  186. "infoNo"=>$infoNo,
  187. "zxNo"=>$zxNo,
  188. "spuCode"=>"",
  189. "good_name"=>$value['good_name'],
  190. "good_img"=>$value['good_img'],
  191. "cat_id"=>$value['cat_id'],
  192. "unit"=>$value['unit'],
  193. "brand_id"=>$value['brand_id'],
  194. "arrival_time"=>$value['arrival_time'],
  195. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  196. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  197. "is_addrs"=>$value['is_addrs'],
  198. "is_custom"=>$value['is_custom'],
  199. "metal_id"=>$value['metal_id'],
  200. "config"=>isset($value['config'])?$value['config']:"",
  201. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  202. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  203. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  204. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  205. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  206. "budget_price"=>$value['budget_price'],
  207. "num"=>$value['num'],
  208. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  209. "use_desc"=>$value['use_desc'],
  210. "remark"=>$value['remark'],
  211. "status"=>1,
  212. "is_del"=>0,
  213. "addtime"=>date("Y-m-d H:i:s"),
  214. "updatetime"=>date("Y-m-d H:i:s"),
  215. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  216. ];
  217. $up = Db::name("consult_info")->insert($info);
  218. if(!$up){
  219. Db::rollback();
  220. return error_show(1004,'添加失败');
  221. }else{
  222. //修改状态,添加待办
  223. ActionLog::logAdd($this->post['token'], [
  224. "order_code" => $infoNo,//咨询单详情编号
  225. "status" => 1,//这里的status是之前的值
  226. "action_remark" => '',//备注
  227. "action_type" => "create"//新建create,编辑edit,更改状态status
  228. ], "ZXD", 1, $info);
  229. ProcessOrder::AddProcess($this->post['token'], [
  230. "order_type" => 'ZXD',
  231. "order_code" => $infoNo,//咨询单详情编号
  232. "order_id" => 0,
  233. "order_status" => 1
  234. ]);
  235. }
  236. }
  237. $stn = ["order_code"=>$zxNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  238. ActionLog::logAdd($this->post['token'],$stn,"ZXD",2,$info);
  239. $process=["order_code"=>$zxNo,"order_id"=>Db::name("consult_order")->getLastInsID(),"order_status"=>1,"order_type"=>'ZXD'];
  240. ProcessOrder::AddProcess($this->post['token'],$process);
  241. Db::commit();
  242. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  243. }else{
  244. Db::rollback();
  245. return error_show(1004,"新建失败");
  246. }
  247. }catch (\Exception $e){
  248. Db::rollback();
  249. return error_show(1003,$e->getMessage());
  250. }
  251. }
  252. public function zxinfo(){
  253. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  254. if($infoNo==""){
  255. return error_show(1004,"参数infoNo不能为空");
  256. }
  257. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  258. if($zxinfo==false){
  259. return error_show(1004,"未找到信息数据");
  260. }
  261. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  262. if($zxorder==false){
  263. return error_show(1004,"未找到咨询信息数据");
  264. }
  265. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  266. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  267. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  268. $zxinfo['khname']="";
  269. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  270. $zxinfo['khNo']="";
  271. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  272. $zxinfo['brand']="";
  273. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  274. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  275. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  276. $zxinfo['company']="";
  277. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  278. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  279. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  280. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  281. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  282. $zxinfo['project_name']="";
  283. $zxinfo['budget_total']="";
  284. $zxinfo['departinfo']=[];
  285. $zxinfo['unit_name']="";
  286. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  287. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  288. if($zxorder['khNo']!==""){
  289. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  290. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  291. $zxinfo['khNo']= $zxorder['khNo'];
  292. }
  293. if($zxinfo['unit']!==""){
  294. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  295. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  296. }
  297. if($zxinfo['brand_id']!==""){
  298. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  299. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  300. }
  301. if($zxorder['companyNo']!==""){
  302. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  303. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  304. }
  305. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  306. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  307. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  308. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  309. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  310. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  311. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  312. }
  313. if($zxorder['depart']>0){
  314. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  315. }
  316. if($zxorder['platform_code']>0){
  317. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  318. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  319. }
  320. return app_show(0,"获取成功",$zxinfo);
  321. }
  322. public function zxedit(){
  323. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  324. if($infoNo==""){
  325. return error_show(1004,"参数infoNo不能为空");
  326. }
  327. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  328. if($zxinfo==false){
  329. return error_show(1004,"未找到信息数据");
  330. }
  331. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  332. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  333. if($good_name==""){
  334. return error_show(1003,"参数good_name不能为空");
  335. }
  336. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  337. if($good_img==""){
  338. return error_show(1003,"参数good_img不能为空");
  339. }
  340. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  341. if($cat_id==""){
  342. return error_show(1003,"参数cat_id不能为空");
  343. }
  344. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  345. if($unit==""){
  346. return error_show(1003,"参数unit不能为空");
  347. }
  348. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  349. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  350. if($arrival_time==""){
  351. return error_show(1003,"参数arrival_time不能为空");
  352. }
  353. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  354. if($specin==""){
  355. return error_show(1003,"参数specinfo不能为空");
  356. }
  357. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  358. // if($cost_desc==""){
  359. // return error_show(1003,"参数cost_desc不能为空");
  360. // }
  361. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  362. if($is_addrs===""){
  363. return error_show(1003,"参数is_addrs不能为空");
  364. }
  365. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  366. if($is_custom===""){
  367. return error_show(1003,"参数is_custom不能为空");
  368. }
  369. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  370. if($metal_id===""){
  371. return error_show(1003,"参数metal_id不能为空");
  372. }
  373. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  374. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  375. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  376. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  377. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  378. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  379. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  380. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  381. if($num===""){
  382. return error_show(1003,"参数num不能为空");
  383. }
  384. if($budget_price===""){
  385. return error_show(1003,"参数budget_price不能为空");
  386. }
  387. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  388. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  389. if($use_desc==""){
  390. return error_show(1003,"参数use_desc不能为空");
  391. }
  392. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  393. if($remark==""){
  394. return error_show(1003,"参数remark不能为空");
  395. }
  396. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  397. if($endtime==""){
  398. return error_show(1003,"参数endtime不能为空");
  399. }
  400. if($metal_id!=0){
  401. if($config==""){
  402. return error_show(1003,"参数config不能为空");
  403. }
  404. if($other_config==""){
  405. return error_show(1003,"参数other_config不能为空");
  406. }
  407. if($specs_weight===""){
  408. return error_show(1003,"参数specs_weight不能为空");
  409. }
  410. if($gold_price===""){
  411. return error_show(1003,"参数gold_price不能为空");
  412. }
  413. }
  414. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  415. if($token==''){
  416. return error_show(102,"参数token不能为空");
  417. }
  418. $user =GetUserInfo($token);
  419. if(empty($user)||$user['code']!=0){
  420. return error_show(105,"用户数据不存在");
  421. }
  422. $specinfo=[];
  423. foreach ($specin as $v){
  424. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  425. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  426. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  427. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  428. $specinfo[]=$v;
  429. }
  430. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  431. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  432. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  433. Db::startTrans();
  434. try{
  435. $innew =makeNo("IF");
  436. $info=[
  437. "infoNo"=>$innew,
  438. "zxNo"=>$zxinfo['zxNo'],
  439. "spuCode"=>"",
  440. "good_name"=>$good_name,
  441. "good_img"=>$good_img,
  442. "cat_id"=>$cat_id,
  443. "unit"=>$unit,
  444. "brand_id"=>$brand_id,
  445. "arrival_time"=>$arrival_time,
  446. "specinfo"=>json_encode($specinfo),
  447. // "color"=>$color,
  448. // "material"=>$material,
  449. "cost_desc"=>$cost_desc,
  450. "is_addrs"=>$is_addrs,
  451. "is_custom"=>$is_custom,
  452. "metal_id"=>$metal_id,
  453. "config"=>$config,
  454. "other_config"=>$other_config,
  455. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  456. "gold_price"=>$gold_price===""? 0 : $gold_price,
  457. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  458. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  459. "budget_price"=>$budget_price,
  460. "num"=>$num,
  461. "pgNo"=>$pgNo,
  462. "use_desc"=>$use_desc,
  463. "remark"=>$remark,
  464. "status"=>1,
  465. "is_del"=>0,
  466. "addtime"=>date("Y-m-d H:i:s"),
  467. "updatetime"=>date("Y-m-d H:i:s"),
  468. 'bargain_status'=>1,
  469. 'enclosure_file'=>$enclosure_file
  470. ];
  471. $up = Db::name("consult_info")->insert($info);
  472. if($up){
  473. //修改状态,添加待办
  474. ActionLog::logAdd($this->post['token'], [
  475. "order_code" => $innew,//咨询单详情编号
  476. "status" => 1,//这里的status是之前的值
  477. "action_remark" => '',//备注
  478. "action_type" => "create"//新建create,编辑edit,更改状态status
  479. ], "ZXD", 1, $info);
  480. ProcessOrder::AddProcess($this->post['token'], [
  481. "order_type" => 'ZXD',
  482. "order_code" => $innew,//咨询单详情编号
  483. "order_id" => 0,
  484. "order_status" => 1
  485. ]);
  486. if (!empty($bidlist)){
  487. foreach ($bidlist as $value){
  488. unset($value['id']);
  489. $value['infoNo']=$innew;
  490. $value['bidNo']=makeNo("BD");
  491. $value['spuCode']=makeNo("SKU");
  492. $value['status'] =0;
  493. $value['updatetime'] =date("Y-m-d H:i:s");
  494. $in = Db::name("consult_bids")->insert($value);
  495. if($in==false){
  496. Db::rollback();
  497. return error_show(1004,"反馈商品新建失败");
  498. }
  499. }
  500. }
  501. $zxinfo["bargain_status"] =1;
  502. $zxinfo["bargain_code"] =$innew;
  503. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  504. $bar=Db::name("consult_info")->save($zxinfo);
  505. if($bar==false){
  506. Db::rollback();
  507. return error_show(1004,"反馈商品更新失败");
  508. }else{
  509. //修改状态,添加待办
  510. ActionLog::logAdd($this->post['token'], [
  511. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  512. "status" => $zxinfo['status'],//这里的status是之前的值
  513. "action_remark" => '',//备注
  514. "action_type" => "edit"//新建create,编辑edit,更改状态status
  515. ], "ZXD", $zxinfo['status'], $zxinfo);
  516. // 并没有修改状态
  517. // ProcessOrder::AddProcess($this->post['token'], [
  518. // "order_type" => 'ZXD',
  519. // "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  520. // "order_id" => $zxinfo['id'],
  521. // "order_status" => $zxinfo['status']
  522. // ]);
  523. }
  524. //更新consule_order记录
  525. Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,'updatetime'=>date('Y-m-d H:i:s')]);
  526. Db::commit();
  527. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  528. }
  529. }catch (\Exception $e){
  530. Db::rollback();
  531. return error_show(1004,$e->getMessage());
  532. }
  533. }
  534. //** 发布竞标任务 */
  535. public function bargain(){
  536. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  537. if($infoNo==""){
  538. return error_show(1004,"参数infoNo不能为空");
  539. }
  540. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  541. if($zxinfo==false){
  542. return error_show(1004,"未找到信息数据");
  543. }
  544. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  545. if($status===""){
  546. return error_show(1004,"参数status不能为空");
  547. }
  548. if($status==1&&$zxinfo['status']>1){
  549. $zxinfo['bargain_num']=+1;
  550. }
  551. $old_zxinfo_status = $zxinfo['status'];
  552. $zxinfo['status']=$status;
  553. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  554. $up = Db::name("consult_info")->save($zxinfo);
  555. if($up){
  556. //修改状态,添加待办
  557. ActionLog::logAdd($this->post['token'], [
  558. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  559. "status" => $old_zxinfo_status,//这里的status是之前的值
  560. "action_remark" => '',//备注
  561. "action_type" => "status"//新建create,编辑edit,更改状态status
  562. ], "ZXD", $zxinfo['status'], $zxinfo);
  563. ProcessOrder::AddProcess($this->post['token'], [
  564. "order_type" => 'ZXD',
  565. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  566. "order_id" => $zxinfo['id'],
  567. "order_status" => $zxinfo['status']
  568. ]);
  569. return app_show(0,"状态更新成功");
  570. }else{
  571. return error_show(1003,"状态更新失败");
  572. }
  573. }
  574. public function feadback(){
  575. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  576. if($infoNo==""){
  577. return error_show(1002,"参数infoNo不能为空");
  578. }
  579. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  580. if($zxinfo==false){
  581. return error_show(1003,"未找到信息数据");
  582. }
  583. if($zxinfo['status']!=1){
  584. return error_show(1004,"任务未进行");
  585. }
  586. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  587. if($zx==false){
  588. return error_show(1003,"未找咨询信息数据");
  589. }
  590. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  591. if($pname==""){
  592. return error_show(1002,"参数pname不能为空");
  593. }
  594. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  595. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  596. if($cat_id==""){
  597. return error_show(1002,"参数cat_id不能为空");
  598. }
  599. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  600. if($specin==""){
  601. return error_show(1003,"参数specinfo不能为空");
  602. }
  603. $specinfo=[];
  604. foreach ($specin as $v){
  605. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  606. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  607. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  608. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  609. $specinfo[]=$v;
  610. }
  611. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  612. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  613. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  614. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  615. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  616. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  617. :"";
  618. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  619. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  620. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  621. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  622. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  623. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  624. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  625. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  626. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  627. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  628. $good_weight = isset($this->post['good_weight'])&&$this->post['good_weight']!==""? floatval($this->post['good_weight']):"";
  629. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"";
  630. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"";
  631. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"";
  632. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval
  633. ($this->post['pakge_fee']):"";
  634. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"";
  635. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"";
  636. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"";
  637. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"";
  638. if($nake_fee==="" ){
  639. return error_show(1004,"参数nake_fee不能为空");
  640. }
  641. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  642. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  643. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  644. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  645. if($token==''){
  646. return error_show(1002,"参数token不能为空");
  647. }
  648. $user =GetUserInfo($token);
  649. if(empty($user)||$user['code']!=0){
  650. return error_show(1005,"用户数据不存在");
  651. }
  652. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  653. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  654. $bidNo=makeNo("BD");
  655. $spucode=makeNo("SKU");
  656. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  657. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  658. //部分参数的大小校验
  659. $vali = Validate::rule([
  660. 'expire_day|有效时长'=>'require|elt:214748364',
  661. 'delivery_day|物流时长'=>'require|elt:214748364',
  662. 'work_day|生产工期'=>'require|elt:214748364',
  663. 'weight|总重量'=>'require|max:10',
  664. ]);
  665. $temp = [
  666. 'expire_day'=>$expire_day,
  667. 'delivery_day'=>$delivery_day,
  668. 'work_day'=>$work_day,
  669. 'weight'=>$weight,
  670. ];
  671. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  672. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  673. $cat_top_list = made($cat_id);
  674. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  675. if ($is_gold_price == 1 && $cat_top_id == 6) {
  676. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  677. ->find();
  678. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  679. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  680. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  681. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  682. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  683. $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  684. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  685. $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  686. }else{
  687. if($nake_fee){
  688. $saleprice = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee / (1 - $budget);
  689. $total_fee = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  690. }else{
  691. $saleprice = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee / (1 - $budget);
  692. $total_fee = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee;
  693. }
  694. }
  695. $data=[
  696. "bidNo"=>$bidNo,
  697. "infoNo"=>$infoNo,
  698. "zxNo"=>$zxinfo['zxNo'],
  699. "spuCode"=>$spucode,
  700. "good_name"=>$pname,
  701. "brand_id"=>$brandid,
  702. "cat_id"=>$cat_id,
  703. "specinfo"=>json_encode($specinfo),
  704. "unit_id"=>$unit_id,
  705. "cost_desc"=>$cost_desc,
  706. "work_day"=>$work_day,
  707. "delivery_day"=>$delivery_day,
  708. "good_img"=>$good_img,
  709. "expire_day"=>$expire_day,
  710. "origin_place"=>$origin_place,
  711. "supplierNo"=>$supplierNo,
  712. "pay_way"=>$pay_way,
  713. "tax"=>$tax,
  714. "send_way"=>$send_way,
  715. "metal_id"=>$metal_id,
  716. "is_gold_price"=>$is_gold_price,
  717. "config"=>$config,
  718. "other_config"=>$other_config,
  719. "weight"=>$weight,
  720. "good_weight"=>$good_weight,
  721. "is_diff"=>$is_diff,
  722. "demo_fee"=>$demo_fee,
  723. "delivery_fee"=>$delivery_fee,
  724. "open_fee"=>$open_fee,
  725. "pakge_fee"=>$pakge_fee,
  726. "nake_fee"=>$nake_fee,
  727. "mark_fee"=>$mark_fee,
  728. "cert_fee"=>$cert_fee,
  729. "cost_fee"=>$cost_fee,
  730. "total_fee"=>$total_fee,
  731. "supply_area"=>$supply_area,
  732. "remark"=>$remark,
  733. "sale_price"=>$saleprice,
  734. "sale_cost_fee"=>$sale_cost_fee,
  735. "origin_price"=>$saleprice,
  736. "createrid"=>$createrid,
  737. "creater"=>$creater,
  738. "status"=>$zxinfo['status']==1 ?1 :2,
  739. "is_del"=>0,
  740. "addtime"=>date("Y-m-d H:i:s"),
  741. "updatetime"=>date("Y-m-d H:i:s")
  742. ];
  743. Db::startTrans();
  744. try{
  745. $insert= Db::name("consult_bids")->insert($data);
  746. if($insert){
  747. // $data=[
  748. // "spuCode"=>$spucode,
  749. // "good_name"=>$pname,
  750. // "brand_id"=>$brandid,
  751. // "good_unit"=>$unit_id,
  752. // "good_type"=>0,
  753. // "moq"=>1,
  754. // "customized"=>$work_day,
  755. // "tax"=>$tax,
  756. // "supplierNo"=>$supplierNo,
  757. // "is_auth"=>0,
  758. // "craft_desc"=>$cost_desc,
  759. // "good_remark"=>$remark,
  760. // "good_img"=>$good_img,
  761. // "good_thumb_img"=>"",
  762. // "good_info_img"=>"",
  763. // "status"=>1,
  764. // "is_del"=>0,
  765. // "createrid"=>$createrid,
  766. // "creater"=>$creater,
  767. // "addtime"=>date("Y-m-d H:i:s"),
  768. // "updatetime"=>date("Y-m-d H:i:s")
  769. // ];
  770. // $good = Db::name("good_zixun")->insert($data);
  771. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  772. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  773. if($projectinfo==false){
  774. Db::rollback();
  775. return error_show(1006,"未找到项目信息");
  776. }
  777. $temp=[];
  778. $temp['spuCode']=$spucode;
  779. $temp['skuCode']="";
  780. $temp['pgNo']=$zxinfo['pgNo'];
  781. $temp['projectNo']=$zx['projectNo'];
  782. $temp['good_name']=$pname;
  783. $temp['good_type']=$projectinfo['good_type'];
  784. $temp['data_source']=2;
  785. $temp['cat_id']=$cat_id;
  786. $temp['budget_price']=$projectinfo['budget_price'];
  787. $temp['sale_price']=$saleprice;
  788. $temp['origin_price']=$total_fee;
  789. $temp['num']=$zxinfo['num'];
  790. $temp['status']=0;
  791. $temp['is_del']=0;
  792. $temp['creater']=$creater;
  793. $temp['createrid']=$createrid;
  794. $temp['addtime']=date("Y-m-d H:i:s");
  795. $temp['updatetime']=date("Y-m-d H:i:s");
  796. $nu = Db::name("project_feedback")->insert($temp);
  797. if($nu==false){
  798. Db::rollback();
  799. return error_show(1006,"项目反馈失败");
  800. }else{
  801. $old_projectinfo_status = $projectinfo['status'];
  802. $projectinfo['status']=2;
  803. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  804. $up = Db::name("project_info")->save($projectinfo);
  805. if($up){
  806. //修改状态,添加待办,只记录动作
  807. ActionLog::logAdd($this->post['token'], [
  808. "order_code" => $projectinfo['pgNo'],//编码
  809. "status" => $old_projectinfo_status,//这里的status是之前的值
  810. "action_remark" => '',//备注
  811. "action_type" => "status"//新建create,编辑edit,更改状态status
  812. ], "PRO", 2, $projectinfo);
  813. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  814. ->count();
  815. if($count==0){
  816. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  817. if($projetc!=false){
  818. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  819. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  820. if($proc==false){
  821. Db::rollback();
  822. return error_show(1006,"项目反馈失败");
  823. }else{
  824. //修改状态,添加待办
  825. ActionLog::logAdd($this->post['token'], [
  826. "order_code" => $projetc['projectNo'],//项目编码
  827. "status" => 1,//这里的status是之前的值
  828. "action_remark" => '',//备注
  829. "action_type" => "status"//新建create,编辑edit,更改状态status
  830. ], "PRO", 2, $projetc);
  831. ProcessOrder::AddProcess($this->post['token'], [
  832. "order_type" => 'PRO',
  833. "order_code" => $projetc['projectNo'],
  834. "order_id" => $projetc['id'],
  835. "order_status" => 2
  836. ]);
  837. }
  838. }
  839. }
  840. }
  841. }
  842. }
  843. Db::commit();
  844. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  845. }else{
  846. Db::rollback();
  847. return error_show(1006,"反馈失败");
  848. }
  849. }catch (\Exception $e){
  850. Db::rollback();
  851. return error_show(1006,$e->getMessage());
  852. }
  853. }
  854. public function feadinfo(){
  855. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  856. if($bidNo==""){
  857. return error_show(1004,"参数bidNo不能为空");
  858. }
  859. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  860. if($info==false){
  861. return error_show(1004,"未找到商品数据");
  862. }
  863. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  864. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  865. $info['cat_info'] = made($info['cat_id'],[]);
  866. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  867. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  868. if($info['brand_id']!=0){
  869. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  870. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  871. }else{
  872. $info["brand_name"]="";
  873. $info["brand_id"]="";
  874. }
  875. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  876. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  877. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  878. $god=[
  879. "metal_id"=>$info['metal_id'],
  880. "weight"=>$info["weight"],
  881. "demo_fee"=>$info["demo_fee"],
  882. "delivery_fee"=>$info["delivery_fee"],
  883. "open_fee"=>$info["open_fee"],
  884. "packing_fee"=>$info["pakge_fee"],
  885. "mark_fee"=>$info["mark_fee"],
  886. "nake_fee"=>$info["nake_fee"],
  887. "cert_fee"=>$info["cert_fee"],
  888. "cost_fee"=>$info["cost_fee"],
  889. "num"=>$bidinfo["num"],
  890. ];
  891. if($info['is_gold_price']==1){
  892. $price = GoldPrice($god, $budget/100);
  893. $info['sale_price'] =round($price,2);
  894. }
  895. $info['specinfo'] = json_decode($info['specinfo'],true);
  896. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  897. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  898. $info['bargain'] =$bargain;
  899. return app_show(0,"获取成功",$info);
  900. }
  901. public function feededit(){
  902. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  903. if($bidNo==""){
  904. return error_show(1002,"参数bidNo不能为空");
  905. }
  906. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  907. if($bidinfo==false){
  908. return error_show(1003,"未找到信息数据");
  909. }
  910. if($bidinfo['status']>=5){
  911. return error_show(1004,"咨询单已确认无法修改");
  912. }
  913. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  914. if($zxinfo==false){
  915. return error_show(1003,"未找到信息数据");
  916. }
  917. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  918. if($zx==false){
  919. return error_show(1003,"未找咨询信息数据");
  920. }
  921. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  922. if($pname==""){
  923. return error_show(1002,"参数pname不能为空");
  924. }
  925. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  926. // if($brandid==""){
  927. // return error_show(1002,"参数brandid不能为空");
  928. // }
  929. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  930. if($cat_id==""){
  931. return error_show(1002,"参数cat_id不能为空");
  932. }
  933. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  934. if($specin==""){
  935. return error_show(1003,"参数specinfo不能为空");
  936. }
  937. $specinfo=[];
  938. foreach ($specin as $v){
  939. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  940. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  941. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  942. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  943. $specinfo[]=$v;
  944. }
  945. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  946. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  947. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  948. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  949. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  950. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  951. :"";
  952. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  953. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  954. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  955. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  956. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  957. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  958. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  959. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  960. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  961. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"";
  962. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"";
  963. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"";
  964. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"";
  965. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"";
  966. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  967. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"";
  968. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"";
  969. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"";
  970. $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""? floatval($this->post['total_fee']):"";
  971. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  972. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  973. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  974. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  975. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  976. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  977. $cat_top_list = made($cat_id);
  978. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  979. if ($is_gold_price == 1 && $cat_top_id == 6) {
  980. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  981. ->find();
  982. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  983. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  984. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  985. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  986. $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  987. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  988. $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  989. }else{
  990. $saleprice = ($open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  991. $total_fee = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  992. }
  993. Db::startTrans();
  994. try{
  995. $data=[
  996. "good_name"=>$pname,
  997. "brand_id"=>$brandid,
  998. "cat_id"=>$cat_id,
  999. "specinfo"=>json_encode($specinfo),
  1000. // "material"=>$material,
  1001. "unit_id"=>$unit_id,
  1002. "cost_desc"=>$cost_desc,
  1003. "work_day"=>$work_day,
  1004. "delivery_day"=>$delivery_day,
  1005. "good_img"=>$good_img,
  1006. "expire_day"=>$expire_day,
  1007. "origin_place"=>$origin_place,
  1008. "supplierNo"=>$supplierNo,
  1009. "pay_way"=>$pay_way,
  1010. "tax"=>$tax,
  1011. "send_way"=>$send_way,
  1012. "metal_id"=>$metal_id,
  1013. "is_gold_price"=>$is_gold_price,
  1014. "config"=>$config,
  1015. "other_config"=>$other_config,
  1016. "weight"=>$weight,
  1017. "is_diff"=>$is_diff,
  1018. "demo_fee"=>$demo_fee,
  1019. "delivery_fee"=>$delivery_fee,
  1020. "open_fee"=>$open_fee,
  1021. "pakge_fee"=>$pakge_fee,
  1022. "nake_fee"=>$nake_fee,
  1023. "mark_fee"=>$mark_fee,
  1024. "cert_fee"=>$cert_fee,
  1025. "cost_fee"=>$cost_fee,
  1026. "sale_cost_fee"=>$sale_cost_fee,
  1027. "total_fee"=>$total_fee,
  1028. "sale_price"=>$saleprice,
  1029. "supply_area"=>$supply_area,
  1030. "remark"=>$remark,
  1031. "updatetime"=>date("Y-m-d H:i:s")
  1032. ];
  1033. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1034. if($insert){
  1035. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1036. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1037. if($projectinfo==false){
  1038. Db::rollback();
  1039. return error_show(1006,"未找到项目信息");
  1040. }
  1041. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1042. if($feed==false){
  1043. Db::rollback();
  1044. return error_show(1006,"未找到项目反馈信息");
  1045. }
  1046. $feed['good_name']=$pname;
  1047. $feed['good_type']=$projectinfo['good_type'];
  1048. $feed['cat_id']=$cat_id;
  1049. $feed['sale_price']=$saleprice;
  1050. $feed['origin_price']=$total_fee;
  1051. $feed['updatetime']=date("Y-m-d H:i:s");
  1052. $temp['updatetime']=date("Y-m-d H:i:s");
  1053. $nu = Db::name("project_feedback")->save($feed);
  1054. if($nu==false){
  1055. Db::rollback();
  1056. return error_show(1006,"项目反馈失败");
  1057. }else{
  1058. $old_projectinfo_status = $projectinfo['status'];
  1059. $projectinfo['status']=2;
  1060. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1061. $up = Db::name("project_info")->save($projectinfo);
  1062. if($up){
  1063. //修改状态,添加待办,只记录动作
  1064. ActionLog::logAdd($this->post['token'], [
  1065. "order_code" => $projectinfo['pgNo'],//编码
  1066. "status" => $old_projectinfo_status,//这里的status是之前的值
  1067. "action_remark" => '',//备注
  1068. "action_type" => "status"//新建create,编辑edit,更改状态status
  1069. ], "PRO", 2, $projectinfo);
  1070. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->count();
  1071. if ($count == 0) {
  1072. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1073. $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->value('id', 0);
  1074. if ($project_id) {
  1075. $proc = Db::name("project")->where(["id" => $project_id])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1076. if ($proc == false) {
  1077. Db::rollback();
  1078. return error_show(1006, "项目反馈失败");
  1079. }else{
  1080. //修改状态,添加待办
  1081. ActionLog::logAdd($this->post['token'], [
  1082. "order_code" => $projectinfo['projectNo'],//项目编码
  1083. "status" => 1,//这里的status是之前的值
  1084. "action_remark" => '',//备注
  1085. "action_type" => "status"//新建create,编辑edit,更改状态status
  1086. ], "PRO", 2, $this->post);
  1087. ProcessOrder::AddProcess($this->post['token'], [
  1088. "order_type" => 'PRO',
  1089. "order_code" => $projectinfo['projectNo'],
  1090. "order_id" => $project_id,
  1091. "order_status" => 2
  1092. ]);
  1093. }
  1094. }
  1095. }
  1096. }
  1097. }
  1098. }
  1099. Db::commit();
  1100. return app_show(0,"编辑成功");
  1101. }else{
  1102. Db::rollback();
  1103. return error_show(1004,"编辑失败");
  1104. }
  1105. }catch (\Exception $e){
  1106. Db::rollback();
  1107. return error_show(1004,$e->getMessage());
  1108. }
  1109. }
  1110. public function bargain_add(){
  1111. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1112. if($bidNo===""){
  1113. return error_show(1004,"参数bidNo不能为空");
  1114. }
  1115. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1116. if($info==false){
  1117. return error_show(1004,"未找到商品数据");
  1118. }
  1119. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1120. if($consult==false){
  1121. return error_show(1004,"未找到咨询数据");
  1122. }
  1123. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1124. if($bargain_price===""){
  1125. return error_show(1004,"参数bargain_price不能为空");
  1126. }
  1127. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1128. if($info['is_gold_price']==1){
  1129. if($cost_price==""){
  1130. return error_show(1004,"参数cost_price不能为空");
  1131. }
  1132. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1133. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1134. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1135. ->find();
  1136. $bargain_price = ($info['open_fee'] / $consult['num'] + $info['weight'] * $gold["price"] + $cost_price *$info['weight'] +
  1137. $info['pakge_fee'] + $info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1138. }
  1139. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1140. // if($bargain_reason===""){
  1141. // return error_show(1004,"参数bargain_reason不能为空");
  1142. // }
  1143. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1144. if($infos==false){
  1145. return error_show(1004,"未找到商品数据");
  1146. }
  1147. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1148. return error_show(1004,"咨询单招标未结束或已确认商品");
  1149. }
  1150. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1151. if($token==''){
  1152. return error_show(105,"参数token不能为空");
  1153. }
  1154. $user =GetUserInfo($token);
  1155. if(empty($user)||$user['code']!=0){
  1156. return error_show(1002,"用户数据不存在");
  1157. }
  1158. //新增两个字段
  1159. //议价备注
  1160. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1161. //议价原因id
  1162. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1163. if ($result_info_id != '') {
  1164. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1165. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1166. }
  1167. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1168. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1169. $bargainNo =makeNo("BA");
  1170. Db::startTrans();//::todo 金价 毛利计算
  1171. try{
  1172. $data=[
  1173. "bidsNo"=>$bidNo,
  1174. "infoNo"=>$info['infoNo'],
  1175. "zxNo"=>$info['zxNo'],
  1176. "bargainNo"=>$bargainNo,
  1177. "bargain_type"=>1,
  1178. "bargain_reason"=>$bargain_reason,
  1179. "sale_price"=>$info['sale_price'],
  1180. "cost_before_price"=>$info['cost_fee'],
  1181. "cost_after_price"=>$cost_price,
  1182. "before_rate"=>round(($info['sale_price']-$info['total_fee'])/$info['sale_price'],2),
  1183. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1184. "after_price"=>$bargain_price,
  1185. "exam_info"=>"",
  1186. "status"=>1,
  1187. "is_del"=>0,
  1188. "creater"=>$creater,
  1189. "createrid"=>$createrid,
  1190. "addtime"=>date("Y-m-d H:i:s"),
  1191. "updatetime"=>date("Y-m-d H:i:s"),
  1192. 'bargain_remark'=>$bargain_remark,
  1193. 'result_info_id'=>$result_info_id,
  1194. ];
  1195. $int = Db::name("bargain_order")->insert($data);
  1196. if($int){
  1197. $info['status']=3;
  1198. $info['updatetime']=date("Y-m-d H:i:s");
  1199. $up =Db::name("consult_bids")->save($info);
  1200. if($up){
  1201. $old_infos_status = $infos['status'];
  1202. $infos['status']=3;
  1203. $infos['updatetime']=date("Y-m-d H:i:s");
  1204. $ups =Db::name("consult_info")->save($infos);
  1205. if($ups){
  1206. //修改状态,添加待办
  1207. ActionLog::logAdd($this->post['token'], [
  1208. "order_code" => $infos['infoNo'],//咨询单详情编号
  1209. "status" => $old_infos_status,//这里的status是之前的值
  1210. "action_remark" => '',//备注
  1211. "action_type" => "status"//新建create,编辑edit,更改状态status
  1212. ], "ZXD", $infos['status'], $infos);
  1213. ProcessOrder::AddProcess($this->post['token'], [
  1214. "order_type" => 'ZXD',
  1215. "order_code" => $infos['infoNo'],//咨询单详情编号
  1216. "order_id" => $infos['id'],
  1217. "order_status" => $infos['status']
  1218. ]);
  1219. Db::commit();
  1220. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1221. }
  1222. }
  1223. }
  1224. Db::rollback();
  1225. return error_show(1004,"议价单新建失败");
  1226. }catch (\Exception $e){
  1227. Db::rollback();
  1228. return error_show(1004,$e->getMessage());
  1229. }
  1230. }
  1231. //选择商品
  1232. public function bids_check(){
  1233. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1234. if($bidNo===""){
  1235. return error_show(1004,"参数bidNo不能为空");
  1236. }
  1237. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1238. if($info==false){
  1239. return error_show(1004,"未找到商品数据");
  1240. }
  1241. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1242. if($infos==false){
  1243. return error_show(1004,"未找到商品数据");
  1244. }
  1245. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1246. return error_show(1004,"咨询单招标未结束或已确认商品");
  1247. }
  1248. Db::startTrans();
  1249. try {
  1250. $info['status']=6;
  1251. $info['updatetime']=date("Y-m-d H:i:s");
  1252. $bids = Db::name("consult_bids")->save($info);
  1253. if($bids){
  1254. $old_infos_status = $infos['status'];
  1255. $infos['status']=4;
  1256. $infos['updatetime']=date("Y-m-d H:i:s");
  1257. $se = Db::name("consult_info")->save($infos);
  1258. if($se){
  1259. //修改状态,添加待办
  1260. ActionLog::logAdd($this->post['token'], [
  1261. "order_code" => $infos['infoNo'],//咨询单详情编号
  1262. "status" => $old_infos_status,//这里的status是之前的值
  1263. "action_remark" => '',//备注
  1264. "action_type" => "status"//新建create,编辑edit,更改状态status
  1265. ], "ZXD", $infos['status'], $infos);
  1266. ProcessOrder::AddProcess($this->post['token'], [
  1267. "order_type" => 'ZXD',
  1268. "order_code" => $infos['infoNo'],//咨询单详情编号
  1269. "order_id" => $infos['id'],
  1270. "order_status" => $infos['status']
  1271. ]);
  1272. Db::commit();
  1273. return app_show(0,"商品确定成功");
  1274. }
  1275. }
  1276. Db::rollback();
  1277. return error_show(1004,"商品确认失败");
  1278. }catch (\Exception $e){
  1279. Db::rollback();
  1280. return error_show(1004,$e->getMessage());
  1281. }
  1282. }
  1283. //议价审核
  1284. /**
  1285. * status:
  1286. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1287. */
  1288. public function bargain_status(){
  1289. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1290. if($bargainNo===""){
  1291. return error_show(1004,"参数bargainNo不能为空");
  1292. }
  1293. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1294. if($info==false){
  1295. return error_show(1004,"未找到议价数据");
  1296. }
  1297. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1298. if($bids==false){
  1299. return error_show(1004,"未找到商品数据");
  1300. }
  1301. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1302. if($coninfo==false){
  1303. return error_show(1004,"未找到咨询单数据");
  1304. }
  1305. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1306. if($status==''){
  1307. return error_show(1005,"参数status不能为空");
  1308. }
  1309. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1310. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1311. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1312. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1313. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1314. if($bids['is_gold_price']==1){
  1315. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1316. ->find();
  1317. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1318. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1319. $saleprice = ($bids['open_fee'] / $coninfo['num'] + $bids['weight']* $gold["price"] + $bids['cost_fee']*$bids['weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee']) / (1 - $budget);
  1320. $rate_price = ($bids['open_fee'] / $coninfo['num'] + $bids['weight']* $gold["price"] +$bids['cost_fee']*$bids['weight'] +$bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee']) / (1 - $rate);
  1321. $money_price = ($bids['open_fee'] / $coninfo['num'] + $bids['weight']* $gold["price"] +$bids['cost_fee']*$bids['weight'] +$bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee']) / (1 - $money_rate);
  1322. $lower_price = ($bids['open_fee'] / $coninfo['num'] + $bids['weight']* $gold["price"] +$bids['cost_fee']*$bids['weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee']) / (1 - $lower_rate);
  1323. }else{
  1324. if($bids['nake_fee']!=0){
  1325. $saleprice = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee']/ (1 - $budget);
  1326. $rate_price = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee']/ (1 - $rate);
  1327. $money_price =$bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee']/ (1 - $money_rate);
  1328. $lower_price = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'] / (1 - $lower_rate);
  1329. }else{
  1330. $saleprice = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] / (1 - $budget);
  1331. $rate_price =$bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee']/ (1 - $rate);
  1332. $money_price = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] / (1 - $money_rate);
  1333. $lower_price = $bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] / (1 - $lower_rate);
  1334. }
  1335. }
  1336. if($status==1){
  1337. if($info['status']==0){
  1338. if($info['after_price']<$rate_price){
  1339. $info['status']=2;
  1340. }else{
  1341. $info['status']=1;
  1342. }
  1343. }
  1344. if($info['status']==2){
  1345. $info['status']=4;
  1346. }
  1347. if($info['status']==4||$info['status']==5){
  1348. if($info['after_price']<$money_price){
  1349. $info['status']=7;
  1350. }else{
  1351. $info['status']=6;
  1352. }
  1353. }
  1354. if($info['status']==7){
  1355. if($info['after_price']<$lower_price){
  1356. $info['status']=10;
  1357. }else{
  1358. $info['status']=9;
  1359. }
  1360. }
  1361. }else{
  1362. if($info['status']==0){
  1363. $info['status']=3;
  1364. }
  1365. if($info['status']==2){
  1366. $info['status']=5;
  1367. }
  1368. if($info['status']==4||$info['status']==5){
  1369. $info['status']=8;
  1370. }
  1371. if($info['status']==7){
  1372. $info['status']=11;
  1373. }
  1374. }
  1375. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1376. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1377. if($token==''){
  1378. return error_show(105,"参数token不能为空");
  1379. }
  1380. $user =GetUserInfo($token);
  1381. if(empty($user)||$user['code']!=0){
  1382. return error_show(1002,"用户数据不存在");
  1383. }
  1384. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1385. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1386. Db::startTrans();
  1387. try{
  1388. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1389. $examinfo[]=["status"=>$status,"remark"=>$remark,"createrid"=>$createrid,"creater"=>$creater];
  1390. $info['status'] =$status;
  1391. $info['remark'] =$remark;
  1392. $info['exam_info']=json_encode($examinfo) ;
  1393. $info['updatetime'] =date("Y-m-d H:i:s");
  1394. $up =Db::name("bargain_order")->save($info);
  1395. if($up){
  1396. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1397. $bids['status']=5;
  1398. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1399. $bids['sale_price']=$info['after_price'];
  1400. if($bids['is_gold_price']==1){
  1401. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1402. // ->find();
  1403. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1404. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1405. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1406. }
  1407. }
  1408. $bids['updatetime']=date("Y-m-d H:i:s");
  1409. $up =Db::name("consult_bids")->save($bids);
  1410. if($up==false){
  1411. Db::rollback();
  1412. return error_show(1004,"数据更新失败");
  1413. }
  1414. }
  1415. Db::commit();
  1416. return app_show(0,"更新成功");
  1417. }
  1418. }catch (\Exception $e){
  1419. Db::rollback();
  1420. return error_show(1004,$e->getMessage());
  1421. }
  1422. }
  1423. public function bargain_info(){
  1424. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1425. if($bargainNo===""){
  1426. return error_show(1004,"参数bargainNo不能为空");
  1427. }
  1428. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1429. if($info==false){
  1430. return error_show(1004,"未找到议价数据");
  1431. }
  1432. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1433. if($bidinfos==false){
  1434. return error_show(1004,"未找到商品数据");
  1435. }
  1436. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1437. ->find();
  1438. if($consultinfos==false){
  1439. return error_show(1004,"未找到咨询商品数据");
  1440. }
  1441. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1442. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1443. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1444. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1445. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1446. $info['before_rate'] = $info['before_rate']*100;
  1447. $info['after_rate'] = $info['after_rate']*100;
  1448. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_encode($info['exam_info']):"";
  1449. if($bidinfos['brand_id']!=0){
  1450. $info['brand_id'] = $bidinfos['brand_id'];
  1451. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1452. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1453. }else{
  1454. $info["brand_name"]="";
  1455. $info["brand_id"]="";
  1456. }
  1457. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1458. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1459. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1460. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1461. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1462. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1463. $info['budget'] =$budget;
  1464. $god=[
  1465. "metal_id"=>$bidinfos['metal_id'],
  1466. "weight"=>$bidinfos["weight"],
  1467. "demo_fee"=>$bidinfos["demo_fee"],
  1468. "delivery_fee"=>$bidinfos["delivery_fee"],
  1469. "open_fee"=>$bidinfos["open_fee"],
  1470. "packing_fee"=>$bidinfos["pakge_fee"],
  1471. "mark_fee"=>$bidinfos["mark_fee"],
  1472. "nake_fee"=>$bidinfos["nake_fee"],
  1473. "cert_fee"=>$bidinfos["cert_fee"],
  1474. "cost_fee"=>$bidinfos["cost_fee"],
  1475. "num"=>$bidinfoe["num"],
  1476. ];
  1477. $info['gold_price']=0;
  1478. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1479. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1480. ->find();
  1481. $info['gold_price'] =$gold['price'];
  1482. }
  1483. $info['cost_desc'] =$bidinfos['cost_desc'];
  1484. $info['work_day'] =$bidinfos['work_day'];
  1485. $info['delivery_day'] =$bidinfos['delivery_day'];
  1486. $info['expire_day'] =$bidinfos['expire_day'];
  1487. $info['origin_place'] =$bidinfos['origin_place'];
  1488. $info['origin_addr'] ="";
  1489. if($bidinfos['origin_place']!=''){
  1490. $code = explode(",",$bidinfos['origin_place']);
  1491. $temp=[];
  1492. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1493. $temp['city_code']=isset($code[1])?$code[1]:"";
  1494. $temp['area_code']=isset($code[2])?$code[2]:"";
  1495. $addr= GetAddr(json_encode($temp));
  1496. $info['origin_addr'] = $addr;
  1497. }
  1498. $info['supplierNo'] =$bidinfos['supplierNo'];
  1499. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1500. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1501. $info['pay_way'] =$bidinfos['pay_way'];
  1502. $info['tax'] =$bidinfos['tax'];
  1503. $info['send_way'] =$bidinfos['send_way'];
  1504. $info['metal_id'] =$bidinfos['metal_id'];
  1505. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1506. $info['config'] =$bidinfos['config'];
  1507. $info['other_config'] =$bidinfos['other_config'];
  1508. $info['weight'] =$bidinfos['weight'];
  1509. $info['is_diff'] =$bidinfos['is_diff'];
  1510. $info['demo_fee'] =$bidinfos['demo_fee'];
  1511. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1512. $info['open_fee'] =$bidinfos['open_fee'];
  1513. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1514. $info['nake_fee'] =$bidinfos['nake_fee'];
  1515. $info['mark_fee'] =$bidinfos['mark_fee'];
  1516. $info['cert_fee'] =$bidinfos['cert_fee'];
  1517. $info['cost_fee'] =$bidinfos['cost_fee'];
  1518. $info['total_fee'] =$bidinfos['total_fee'];
  1519. $info['supply_area'] =$bidinfos['supply_area'];
  1520. $info['remark'] =$bidinfos['remark'];
  1521. $info['is_addrs'] =$consultinfos['is_addrs'];
  1522. $info['is_custom'] =$consultinfos['is_custom'];
  1523. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1524. $info['sale_price'] =round($bidinfos['sale_price'],2);
  1525. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1526. //获取议价原因
  1527. if ($info['result_info_id'] != 0) {
  1528. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1529. } else {
  1530. $info['result_info'] = '';
  1531. }
  1532. return app_show(0,"获取成功",$info);
  1533. }
  1534. public function bidlist(){
  1535. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1536. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1537. $where=[['is_del',"=",0]];
  1538. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1539. if ($zxNo !== "") {
  1540. $where[] = ['zxNo','=',$zxNo];
  1541. }
  1542. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1543. if ($infoNo !== "") {
  1544. $where[] = ['infoNo','=',$infoNo];
  1545. }
  1546. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1547. if ($bidNo !== "") {
  1548. $where[] = ['bidNo','=',$bidNo];
  1549. }
  1550. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1551. if ($pgNo !== "") {
  1552. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1553. $where[] = ['infoNo','in',$bidinfo];
  1554. }
  1555. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1556. if ($bargain_status !== "") {
  1557. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1558. $where[] = ['infoNo','in',$bidinfo];
  1559. }
  1560. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1561. if ($projectNo !== "") {
  1562. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1563. ("zxNo");
  1564. $where[] = ['zxNo','in',$zxlist];
  1565. }
  1566. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1567. if($is_own==1){
  1568. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1569. if($token==""){
  1570. return error_show(101,'token不能为空');
  1571. }
  1572. $apply_id =GetUserInfo($token);
  1573. if(empty($apply_id)||$apply_id['code']!=0){
  1574. return error_show(1002,"申请人数据不存在");
  1575. }
  1576. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1577. $where[]=['createrid',"=",$rm];
  1578. }
  1579. $count = Db::name('consult_bids')->where($where)->count();
  1580. $total = ceil($count / $size);
  1581. $page = $page >= $total ? $total : $page;
  1582. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1583. $data=[];
  1584. foreach ($list as $value){
  1585. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1586. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1587. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1588. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1589. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1590. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1591. if($value['brand_id']!=0){
  1592. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1593. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1594. }else{
  1595. $value["brand_name"]="";
  1596. $value["brand_id"]="";
  1597. }
  1598. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1599. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1600. $god=[
  1601. "metal_id"=>$value['metal_id'],
  1602. "weight"=>$value["weight"],
  1603. "demo_fee"=>$value["demo_fee"],
  1604. "delivery_fee"=>$value["delivery_fee"],
  1605. "open_fee"=>$value["open_fee"],
  1606. "packing_fee"=>$value["pakge_fee"],
  1607. "mark_fee"=>$value["mark_fee"],
  1608. "nake_fee"=>$value["nake_fee"],
  1609. "cert_fee"=>$value["cert_fee"],
  1610. "cost_fee"=>$value["cost_fee"],
  1611. "num"=>$bidinfo["num"],
  1612. ];
  1613. if($value['is_gold_price']==1){
  1614. $price = GoldPrice($god, $budget/100);
  1615. $value['sale_price'] = round($price,2);
  1616. }
  1617. $value['specinfo'] = json_decode($value['specinfo'],true);
  1618. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1619. $value['bargain_status']=$bidinfo['bargain_status'];
  1620. //reject驳回原因,status==5表示驳回
  1621. $value['reject']=[];
  1622. if ($value['status'] == 5) {
  1623. $value['reject'] = Db::name('bargain_order')
  1624. ->field('id,remark,status')
  1625. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1626. ->whereIn('status', [5, 6])
  1627. ->find();
  1628. }
  1629. //产地
  1630. if($value['origin_place']!=''){
  1631. $code = explode(",",$value['origin_place']);
  1632. $temp=[];
  1633. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1634. $temp['city_code']=isset($code[1])?$code[1]:"";
  1635. $temp['area_code']=isset($code[2])?$code[2]:"";
  1636. $addr= GetAddr(json_encode($temp));
  1637. $value['origin_addr'] = $addr;
  1638. }
  1639. $data[] = $value;
  1640. }
  1641. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1642. }
  1643. public function feedlist(){
  1644. $where=[['is_del',"=",0]];
  1645. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1646. if ($zxNo !== "") {
  1647. $where[] = ['zxNo','=',$zxNo];
  1648. }
  1649. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1650. if ($infoNo !== "") {
  1651. $where[] = ['infoNo','=',$infoNo];
  1652. }
  1653. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1654. if ($bidNo !== "") {
  1655. $where[] = ['bidNo','=',$bidNo];
  1656. }
  1657. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1658. if ($projectNo !== "") {
  1659. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1660. ("zxNo");
  1661. $where[] = ['zxNo','in',$zxlist];
  1662. }
  1663. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1664. if($token==''){
  1665. return error_show(102,"参数token不能为空");
  1666. }
  1667. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1668. if($is_own==1){
  1669. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1670. if($token==""){
  1671. return error_show(101,'token不能为空');
  1672. }
  1673. $apply_id =GetUserInfo($token);
  1674. if(empty($apply_id)||$apply_id['code']!=0){
  1675. return error_show(1002,"申请人数据不存在");
  1676. }
  1677. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1678. $where[]=['createrid',"=",$rm];
  1679. }
  1680. $list =Db::name('consult_bids')->where($where)->select();
  1681. $data=[];
  1682. foreach ($list as $value){
  1683. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1684. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1685. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1686. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1687. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1688. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1689. if($value['brand_id']!=0){
  1690. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1691. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1692. }else{
  1693. $value["brand_name"]="";
  1694. $value["brand_id"]="";
  1695. }
  1696. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1697. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1698. $god=[
  1699. "metal_id"=>$value['metal_id'],
  1700. "weight"=>$value["weight"],
  1701. "demo_fee"=>$value["demo_fee"],
  1702. "delivery_fee"=>$value["delivery_fee"],
  1703. "open_fee"=>$value["open_fee"],
  1704. "packing_fee"=>$value["pakge_fee"],
  1705. "mark_fee"=>$value["mark_fee"],
  1706. "nake_fee"=>$value["nake_fee"],
  1707. "cert_fee"=>$value["cert_fee"],
  1708. "cost_fee"=>$value["cost_fee"],
  1709. "num"=>$bidinfo["num"],
  1710. ];
  1711. if($value['is_gold_price']==1){
  1712. $price = GoldPrice($god, $budget/100);
  1713. $value['sale_price'] =round($price,2);
  1714. }
  1715. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1716. $value['specinfo'] = json_decode($value['specinfo'],true);
  1717. $value['bargain_status']=$bidinfo['bargain_status'];
  1718. $data[]=$value;
  1719. }
  1720. return app_show(0,"获取成功",$data);
  1721. }
  1722. public function bragain_list(){
  1723. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1724. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1725. $where=[['is_del',"=",0]];
  1726. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1727. if($bidsNo!=""){
  1728. $where[]=["bidsNo","=",$bidsNo];
  1729. }
  1730. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1731. if ($zxNo !== "") {
  1732. $where[] = ['zxNo','=',$zxNo];
  1733. }
  1734. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1735. if ($infoNo !== "") {
  1736. $where[] = ['infoNo','=',$infoNo];
  1737. }
  1738. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1739. if ($projectNo !== "") {
  1740. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1741. ("zxNo");
  1742. $where[] = ['zxNo','in',$zxlist];
  1743. }
  1744. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1745. if ($pgNo !== "") {
  1746. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1747. $where[] = ['infoNo','in',$bidinfo];
  1748. }
  1749. $count=Db::name("bargain_order")->where($where)->count();
  1750. $total = ceil($count / $size);
  1751. $page = $page >= $total ? $total : $page;
  1752. $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
  1753. $data=[];
  1754. foreach ($list as $value){
  1755. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1756. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1757. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1758. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1759. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1760. if($bidinfos['brand_id']!=0){
  1761. $value['brand_id'] = $bidinfos['brand_id'];
  1762. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1763. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1764. }else{
  1765. $value["brand_name"]="";
  1766. $value["brand_id"]="";
  1767. }
  1768. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1769. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1770. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1771. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1772. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1773. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1774. $value['budget'] =$budget;
  1775. $god=[
  1776. "metal_id"=>$bidinfos['metal_id'],
  1777. "weight"=>$bidinfos["weight"],
  1778. "demo_fee"=>$bidinfos["demo_fee"],
  1779. "delivery_fee"=>$bidinfos["delivery_fee"],
  1780. "open_fee"=>$bidinfos["open_fee"],
  1781. "packing_fee"=>$bidinfos["pakge_fee"],
  1782. "mark_fee"=>$bidinfos["mark_fee"],
  1783. "nake_fee"=>$bidinfos["nake_fee"],
  1784. "cert_fee"=>$bidinfos["cert_fee"],
  1785. "cost_fee"=>$bidinfos["cost_fee"],
  1786. "num"=>$bidinfoe["num"],
  1787. ];
  1788. // if($bidinfos['is_gold_price']==1){
  1789. // $price = GoldPrice($god, $budget/100);
  1790. // }else{
  1791. // $price = GoodPrice($god, $budget/100);
  1792. // }
  1793. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1794. $value['sale_price'] =round($bidinfos['sale_price'],2);
  1795. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1796. $data[]=$value;
  1797. }
  1798. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1799. }
  1800. public function crontablist(){
  1801. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1802. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1803. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1804. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1805. if ($zxNo !== "") {
  1806. $where[] = ['a.zxNo','=',$zxNo];
  1807. }
  1808. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1809. if ($salesman !== "") {
  1810. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1811. $where[]= ["b.salesman",'like',"%$salesman%"];
  1812. }
  1813. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1814. if ($cpName !== "") {
  1815. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1816. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1817. }
  1818. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1819. if ($khNo !== "") {
  1820. // $where['khNo'] = $khNo;
  1821. $where[]= ["b.khNo",'like',"%$khNo%"];
  1822. }
  1823. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1824. if ($start !="") {
  1825. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1826. $where[]= ["a.addtime",'>=',$start];
  1827. }
  1828. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1829. if($end !=""){
  1830. $where[]= ["a.addtime",'<=',$end];
  1831. }
  1832. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1833. if ($status !== "") {
  1834. $where[]= ["a.status",'=',$status];
  1835. }
  1836. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1837. ->count();
  1838. $total = ceil($count / $size);
  1839. $page = $page >= $total ? $total : $page;
  1840. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1841. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  1842. $data=[];
  1843. foreach ($list as $value){
  1844. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1845. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1846. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1847. $value['khname']="";
  1848. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1849. true):[];
  1850. if($value['khNo']!==""){
  1851. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1852. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1853. }
  1854. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1855. $data[]=$value;
  1856. }
  1857. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1858. }
  1859. }