Consult.php 110 KB

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